From d8f45ff1d873a1669d474cfc05f5100cd73f2573 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Thu, 22 Oct 2020 14:57:50 +0200 Subject: [PATCH] Workarounds and documentation of OSX posix incompatibilities --- src/libslic3r/AppConfig.cpp | 3 +++ src/libslic3r/Thread.cpp | 6 ++++-- src/libslic3r/Thread.hpp | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 609fac75d..eb8f8bd63 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -213,8 +213,11 @@ std::string AppConfig::load() void AppConfig::save() { +#ifndef __APPLE__ + // Apple does not implement thread_getname_np() correctly. if (get_current_thread_name() != "slic3r_main") throw CriticalException("Calling AppConfig::save() from a worker thread!"); +#endif // The config is first written to a file with a PID suffix and then moved // to avoid race conditions with multiple instances of Slic3r diff --git a/src/libslic3r/Thread.cpp b/src/libslic3r/Thread.cpp index e72545994..d0f0e1991 100644 --- a/src/libslic3r/Thread.cpp +++ b/src/libslic3r/Thread.cpp @@ -116,8 +116,10 @@ void set_current_thread_name(const char *thread_name) std::string get_current_thread_name() { - char buf[16]; - return std::string(thread_getname_np(buf, 16) == 0 ? buf : ""); +// not supported +// char buf[16]; +// return std::string(thread_getname_np(buf, 16) == 0 ? buf : ""); + throw CriticalException("Not supported"); } #else diff --git a/src/libslic3r/Thread.hpp b/src/libslic3r/Thread.hpp index 75a58a86c..e1052180d 100644 --- a/src/libslic3r/Thread.hpp +++ b/src/libslic3r/Thread.hpp @@ -10,6 +10,7 @@ namespace Slic3r { // Set / get thread name. // pthread_setname_np supports maximum 15 character thread names! (16th character is the null terminator) +// Methods taking the thread as an argument are not supported by OSX. void set_thread_name(std::thread &thread, const char *thread_name); inline void set_thread_name(std::thread &thread, const std::string &thread_name) { set_thread_name(thread, thread_name.c_str()); } void set_thread_name(boost::thread &thread, const char *thread_name); @@ -17,6 +18,7 @@ inline void set_thread_name(boost::thread &thread, const std::string &thread_nam void set_current_thread_name(const char *thread_name); inline void set_current_thread_name(const std::string &thread_name) { set_current_thread_name(thread_name.c_str()); } +// Not supported by OSX. std::string get_current_thread_name(); // To be called somewhere before the TBB threads are spinned for the first time, to