mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-25 15:44:12 -06:00
Follow-up to ae7d6db1d9
Exporting G-code on a worker thread did not work correctly as the worker threads were using user's locale, not "C" locale. The "C" locale is newly enforced to TBB worker threads by name_tbb_thread_pool_threads_set_locale()
This commit is contained in:
parent
e78d647cc2
commit
f9a5ee725d
5 changed files with 23 additions and 6 deletions
|
@ -812,7 +812,7 @@ void Print::auto_assign_extruders(ModelObject* model_object) const
|
||||||
// Slicing process, running at a background thread.
|
// Slicing process, running at a background thread.
|
||||||
void Print::process()
|
void Print::process()
|
||||||
{
|
{
|
||||||
name_tbb_thread_pool_threads();
|
name_tbb_thread_pool_threads_set_locale();
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(info) << "Starting the slicing process." << log_memory_info();
|
BOOST_LOG_TRIVIAL(info) << "Starting the slicing process." << log_memory_info();
|
||||||
for (PrintObject *obj : m_objects)
|
for (PrintObject *obj : m_objects)
|
||||||
|
|
|
@ -693,7 +693,7 @@ void SLAPrint::process()
|
||||||
if (m_objects.empty())
|
if (m_objects.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
name_tbb_thread_pool_threads();
|
name_tbb_thread_pool_threads_set_locale();
|
||||||
|
|
||||||
// Assumption: at this point the print objects should be populated only with
|
// Assumption: at this point the print objects should be populated only with
|
||||||
// the model objects we have to process and the instances are also filtered
|
// the model objects we have to process and the instances are also filtered
|
||||||
|
|
|
@ -188,7 +188,8 @@ std::optional<std::string> get_current_thread_name()
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
// Spawn (n - 1) worker threads on Intel TBB thread pool and name them by an index and a system thread ID.
|
// Spawn (n - 1) worker threads on Intel TBB thread pool and name them by an index and a system thread ID.
|
||||||
void name_tbb_thread_pool_threads()
|
// Also it sets locale of the worker threads to "C" for the G-code generator to produce "." as a decimal separator.
|
||||||
|
void name_tbb_thread_pool_threads_set_locale()
|
||||||
{
|
{
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
if (initialized)
|
if (initialized)
|
||||||
|
@ -233,6 +234,21 @@ void name_tbb_thread_pool_threads()
|
||||||
std::ostringstream name;
|
std::ostringstream name;
|
||||||
name << "slic3r_tbb_" << range.begin();
|
name << "slic3r_tbb_" << range.begin();
|
||||||
set_current_thread_name(name.str().c_str());
|
set_current_thread_name(name.str().c_str());
|
||||||
|
// Set locales of the worker thread to "C".
|
||||||
|
#ifdef _WIN32
|
||||||
|
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
|
||||||
|
std::setlocale(LC_ALL, "C");
|
||||||
|
#else
|
||||||
|
// We are leaking some memory here, because the newlocale() produced memory will never be released.
|
||||||
|
// This is not a problem though, as there will be a maximum one worker thread created per physical thread.
|
||||||
|
uselocale(newlocale(
|
||||||
|
#ifdef __APPLE__
|
||||||
|
LC_ALL_MASK
|
||||||
|
#else // some Unix / Linux / BSD
|
||||||
|
LC_ALL
|
||||||
|
#endif
|
||||||
|
, "C", nullptr));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,8 @@ std::optional<std::string> get_current_thread_name();
|
||||||
|
|
||||||
// To be called somewhere before the TBB threads are spinned for the first time, to
|
// To be called somewhere before the TBB threads are spinned for the first time, to
|
||||||
// give them names recognizible in the debugger.
|
// give them names recognizible in the debugger.
|
||||||
void name_tbb_thread_pool_threads();
|
// Also it sets locale of the worker threads to "C" for the G-code generator to produce "." as a decimal separator.
|
||||||
|
void name_tbb_thread_pool_threads_set_locale();
|
||||||
|
|
||||||
template<class Fn>
|
template<class Fn>
|
||||||
inline boost::thread create_thread(boost::thread::attributes &attrs, Fn &&fn)
|
inline boost::thread create_thread(boost::thread::attributes &attrs, Fn &&fn)
|
||||||
|
|
|
@ -209,8 +209,8 @@ void BackgroundSlicingProcess::process_sla()
|
||||||
|
|
||||||
void BackgroundSlicingProcess::thread_proc()
|
void BackgroundSlicingProcess::thread_proc()
|
||||||
{
|
{
|
||||||
set_current_thread_name("slic3r_BgSlcPcs");
|
set_current_thread_name("slic3r_BgSlcPcs");
|
||||||
name_tbb_thread_pool_threads();
|
name_tbb_thread_pool_threads_set_locale();
|
||||||
|
|
||||||
assert(m_print != nullptr);
|
assert(m_print != nullptr);
|
||||||
assert(m_print == m_fff_print || m_print == m_sla_print);
|
assert(m_print == m_fff_print || m_print == m_sla_print);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue