diff options
author | Vojtech Bubnik <bubnikv@gmail.com> | 2021-09-13 14:04:12 +0300 |
---|---|---|
committer | Vojtech Bubnik <bubnikv@gmail.com> | 2021-09-13 14:04:12 +0300 |
commit | f9a5ee725d71898179b2ec9e22844b977b4f98b6 (patch) | |
tree | 69e3e6c182b3aaf88bf07dffad1ceaae718e4095 /src/libslic3r | |
parent | e78d647cc239966fdbbd91b995b6f5bef3adc710 (diff) |
Follow-up to ae7d6db1d961f85b8e2788d707cef03de7e28fdb
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()
Diffstat (limited to 'src/libslic3r')
-rw-r--r-- | src/libslic3r/Print.cpp | 2 | ||||
-rw-r--r-- | src/libslic3r/SLAPrint.cpp | 2 | ||||
-rw-r--r-- | src/libslic3r/Thread.cpp | 18 | ||||
-rw-r--r-- | src/libslic3r/Thread.hpp | 3 |
4 files changed, 21 insertions, 4 deletions
diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 06052a62f..27dca8243 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -812,7 +812,7 @@ void Print::auto_assign_extruders(ModelObject* model_object) const // Slicing process, running at a background thread. 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(); for (PrintObject *obj : m_objects) diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 0b9dde122..61ff908d3 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -693,7 +693,7 @@ void SLAPrint::process() if (m_objects.empty()) 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 // the model objects we have to process and the instances are also filtered diff --git a/src/libslic3r/Thread.cpp b/src/libslic3r/Thread.cpp index 25c29d273..106da4a78 100644 --- a/src/libslic3r/Thread.cpp +++ b/src/libslic3r/Thread.cpp @@ -188,7 +188,8 @@ std::optional<std::string> get_current_thread_name() #endif // _WIN32 // 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; if (initialized) @@ -233,6 +234,21 @@ void name_tbb_thread_pool_threads() std::ostringstream name; name << "slic3r_tbb_" << range.begin(); 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 } }); } diff --git a/src/libslic3r/Thread.hpp b/src/libslic3r/Thread.hpp index a86123796..9afe13b42 100644 --- a/src/libslic3r/Thread.hpp +++ b/src/libslic3r/Thread.hpp @@ -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 // 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> inline boost::thread create_thread(boost::thread::attributes &attrs, Fn &&fn) |