mirror of
https://github.com/QIDITECH/QIDISlicer.git
synced 2026-02-01 08:28:42 +03:00
update to latest version
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <random>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include <tbb/task_scheduler_observer.h>
|
||||
@@ -67,6 +68,27 @@ template<class Fn> inline boost::thread create_thread(Fn &&fn)
|
||||
return create_thread(attrs, std::forward<Fn>(fn));
|
||||
}
|
||||
|
||||
class ThreadData {
|
||||
public:
|
||||
std::mt19937& random_generator() {
|
||||
if (! m_random_generator_initialized) {
|
||||
std::random_device rd;
|
||||
m_random_generator.seed(rd());
|
||||
m_random_generator_initialized = true;
|
||||
}
|
||||
return m_random_generator;
|
||||
}
|
||||
|
||||
void tbb_worker_thread_set_c_locales();
|
||||
|
||||
private:
|
||||
std::mt19937 m_random_generator;
|
||||
bool m_random_generator_initialized { false };
|
||||
bool m_tbb_worker_thread_c_locales_set { false };
|
||||
};
|
||||
|
||||
ThreadData& thread_data();
|
||||
|
||||
// For unknown reasons and in sporadic cases when GCode export is processing, some participating thread
|
||||
// in tbb::parallel_pipeline has not set locales to "C", probably because this thread is newly spawned.
|
||||
// So in this class method on_scheduler_entry is called for every thread before it starts participating
|
||||
@@ -79,11 +101,7 @@ class TBBLocalesSetter : public tbb::task_scheduler_observer
|
||||
public:
|
||||
TBBLocalesSetter() { this->observe(true); }
|
||||
~TBBLocalesSetter() override { this->observe(false); };
|
||||
|
||||
void on_scheduler_entry(bool is_worker) override;
|
||||
|
||||
private:
|
||||
tbb::enumerable_thread_specific<bool, tbb::cache_aligned_allocator<bool>, tbb::ets_key_usage_type::ets_key_per_instance> m_is_locales_sets{ false };
|
||||
void on_scheduler_entry(bool /* is_worker */) override { thread_data().tbb_worker_thread_set_c_locales(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user