Workaround for OSX non-compliant implementation of
pthread_getname_np / pthread_setname_np
This commit is contained in:
parent
0d2c31d0e4
commit
723406dfea
@ -2,6 +2,7 @@
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "AppConfig.hpp"
|
||||
#include "Exception.hpp"
|
||||
#include "Thread.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@ -212,6 +213,9 @@ std::string AppConfig::load()
|
||||
|
||||
void AppConfig::save()
|
||||
{
|
||||
if (get_current_thread_name() != "slic3r_main")
|
||||
throw CriticalException("Calling AppConfig::save() from a worker thread!");
|
||||
|
||||
// The config is first written to a file with a PID suffix and then moved
|
||||
// to avoid race conditions with multiple instances of Slic3r
|
||||
const auto path = config_path();
|
||||
|
@ -92,6 +92,36 @@ std::string get_current_thread_name()
|
||||
|
||||
#else // _WIN32
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
// Appe screwed the Posix norm.
|
||||
void set_thread_name(std::thread &thread, const char *thread_name)
|
||||
{
|
||||
// not supported
|
||||
// pthread_setname_np(thread.native_handle(), thread_name);
|
||||
throw CriticalException("Not supported");
|
||||
}
|
||||
|
||||
void set_thread_name(boost::thread &thread, const char *thread_name)
|
||||
{
|
||||
// not supported
|
||||
// pthread_setname_np(thread.native_handle(), thread_name);
|
||||
throw CriticalException("Not supported");
|
||||
}
|
||||
|
||||
void set_current_thread_name(const char *thread_name)
|
||||
{
|
||||
pthread_setname_np(thread_name);
|
||||
}
|
||||
|
||||
std::string get_current_thread_name()
|
||||
{
|
||||
char buf[16];
|
||||
return std::string(thread_getname_np(buf, 16) == 0 ? buf : "");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// posix
|
||||
void set_thread_name(std::thread &thread, const char *thread_name)
|
||||
{
|
||||
@ -114,6 +144,8 @@ std::string get_current_thread_name()
|
||||
return std::string(pthread_getname_np(pthread_self(), buf, 16) == 0 ? buf : "");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
// Spawn (n - 1) worker threads on Intel TBB thread pool and name them by an index and a system thread ID.
|
||||
|
Loading…
Reference in New Issue
Block a user