Fixes of previous commit on Posix platforms

This commit is contained in:
Vojtech Bubnik 2020-10-22 14:29:40 +02:00
parent 81b6883710
commit 6e2a5419cc
2 changed files with 11 additions and 13 deletions

View File

@ -16,10 +16,9 @@
#include "Thread.hpp" #include "Thread.hpp"
#ifdef _WIN32
namespace Slic3r { namespace Slic3r {
#ifdef _WIN32
#ifdef SLIC3R_THREAD_NAME_WIN32_MODERN #ifdef SLIC3R_THREAD_NAME_WIN32_MODERN
static void WindowsSetThreadName(HANDLE hThread, const char *thread_name) static void WindowsSetThreadName(HANDLE hThread, const char *thread_name)
@ -84,7 +83,7 @@ void set_current_thread_name(const char *thread_name)
WindowsSetThreadName(::GetCurrentThread(), thread_name); WindowsSetThreadName(::GetCurrentThread(), thread_name);
} }
void std::string get_current_thread_name() const std::string get_current_thread_name()
{ {
wchar_t *ptr = nullptr; wchar_t *ptr = nullptr;
::GetThreadDescription(::GetCurrentThread(), &ptr); ::GetThreadDescription(::GetCurrentThread(), &ptr);
@ -96,20 +95,20 @@ void std::string get_current_thread_name() const
// posix // posix
void set_thread_name(std::thread &thread, const char *thread_name) void set_thread_name(std::thread &thread, const char *thread_name)
{ {
pthread_setname_np(thread->native_handle(), thread_name); pthread_setname_np(thread.native_handle(), thread_name);
} }
void set_thread_name(boost::thread &thread, const char *thread_name) void set_thread_name(boost::thread &thread, const char *thread_name)
{ {
pthread_setname_np(thread->native_handle(), thread_name); pthread_setname_np(thread.native_handle(), thread_name);
} }
void set_current_thread_name(const char *thread_name) void set_current_thread_name(const char *thread_name)
{ {
set_thread_name(pthread_self(), thread_name); pthread_setname_np(pthread_self(), thread_name);
} }
void std::string get_current_thread_name() const std::string get_current_thread_name()
{ {
char buf[16]; char buf[16];
return std::string(pthread_getname_np(pthread_self(), buf, 16) == 0 ? buf : ""); return std::string(pthread_getname_np(pthread_self(), buf, 16) == 0 ? buf : "");
@ -133,10 +132,8 @@ void name_tbb_thread_pool_threads()
nthreads = 1; nthreads = 1;
#endif #endif
if (nthreads != nthreads_hw) { if (nthreads != nthreads_hw)
static tbb::task_scheduler_init *tbb_init = nullptr; new tbb::task_scheduler_init(nthreads);
tbb_init = new tbb::task_scheduler_init(nthreads);
}
std::atomic<size_t> nthreads_running(0); std::atomic<size_t> nthreads_running(0);
std::condition_variable cv; std::condition_variable cv;
@ -163,7 +160,7 @@ void name_tbb_thread_pool_threads()
assert(range.begin() > 0); assert(range.begin() > 0);
std::ostringstream name; std::ostringstream name;
name << "slic3r_tbb_" << range.begin(); name << "slic3r_tbb_" << range.begin();
set_current_thread_name(name.str()); set_current_thread_name(name.str().c_str());
} }
}); });
} }

View File

@ -2,6 +2,7 @@
#define GUI_THREAD_HPP #define GUI_THREAD_HPP
#include <utility> #include <utility>
#include <string>
#include <thread> #include <thread>
#include <boost/thread.hpp> #include <boost/thread.hpp>
@ -16,7 +17,7 @@ inline void set_thread_name(boost::thread &thread, const std::string &thread_nam
void set_current_thread_name(const char *thread_name); 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()); } inline void set_current_thread_name(const std::string &thread_name) { set_current_thread_name(thread_name.c_str()); }
void std::string get_current_thread_name() const; 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.