From 6e2a5419cc83fdd749bcb0f17b4858294ec2b259 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Thu, 22 Oct 2020 14:29:40 +0200 Subject: [PATCH] Fixes of previous commit on Posix platforms --- src/libslic3r/Thread.cpp | 21 +++++++++------------ src/libslic3r/Thread.hpp | 3 ++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/Thread.cpp b/src/libslic3r/Thread.cpp index 58684a4dd..72065e8f4 100644 --- a/src/libslic3r/Thread.cpp +++ b/src/libslic3r/Thread.cpp @@ -16,10 +16,9 @@ #include "Thread.hpp" -#ifdef _WIN32 - namespace Slic3r { +#ifdef _WIN32 #ifdef SLIC3R_THREAD_NAME_WIN32_MODERN 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); } -void std::string get_current_thread_name() const +std::string get_current_thread_name() { wchar_t *ptr = nullptr; ::GetThreadDescription(::GetCurrentThread(), &ptr); @@ -96,20 +95,20 @@ void std::string get_current_thread_name() const // posix 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) { - 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) { - 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]; return std::string(pthread_getname_np(pthread_self(), buf, 16) == 0 ? buf : ""); @@ -133,10 +132,8 @@ void name_tbb_thread_pool_threads() nthreads = 1; #endif - if (nthreads != nthreads_hw) { - static tbb::task_scheduler_init *tbb_init = nullptr; - tbb_init = new tbb::task_scheduler_init(nthreads); - } + if (nthreads != nthreads_hw) + new tbb::task_scheduler_init(nthreads); std::atomic nthreads_running(0); std::condition_variable cv; @@ -163,7 +160,7 @@ void name_tbb_thread_pool_threads() assert(range.begin() > 0); std::ostringstream name; name << "slic3r_tbb_" << range.begin(); - set_current_thread_name(name.str()); + set_current_thread_name(name.str().c_str()); } }); } diff --git a/src/libslic3r/Thread.hpp b/src/libslic3r/Thread.hpp index 8950cd3d3..75a58a86c 100644 --- a/src/libslic3r/Thread.hpp +++ b/src/libslic3r/Thread.hpp @@ -2,6 +2,7 @@ #define GUI_THREAD_HPP #include +#include #include #include @@ -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); 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 // give them names recognizible in the debugger.