Support for naming slicer own threads for debugging.

The following threads are named with this commit:
slic3r_main, slic3r_BackgroundSlicingProcess,
slic3r_tbbpool_xx_yy where xx is a one based index of the TTB thread
and yy is the platform thread ID.
This commit is contained in:
Vojtech Bubnik 2020-10-22 13:53:08 +02:00
parent 8d59abfdf8
commit 6531061d09
12 changed files with 219 additions and 38 deletions

40
src/libslic3r/Thread.hpp Normal file
View file

@ -0,0 +1,40 @@
#ifndef GUI_THREAD_HPP
#define GUI_THREAD_HPP
#include <utility>
#include <thread>
#include <boost/thread.hpp>
namespace Slic3r {
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);
inline void set_thread_name(boost::thread &thread, const std::string &thread_name) { set_thread_name(thread, thread_name.c_str()); }
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()); }
// To be called somewhere before the TBB threads are spinned for the first time, to
// give them names recognizible in the debugger.
void name_tbb_thread_pool_threads();
template<class Fn>
inline boost::thread create_thread(boost::thread::attributes &attrs, Fn &&fn)
{
// Duplicating the stack allocation size of Thread Building Block worker
// threads of the thread pool: allocate 4MB on a 64bit system, allocate 2MB
// on a 32bit system by default.
attrs.set_stack_size((sizeof(void*) == 4) ? (2048 * 1024) : (4096 * 1024));
return boost::thread{attrs, std::forward<Fn>(fn)};
}
template<class Fn> inline boost::thread create_thread(Fn &&fn)
{
boost::thread::attributes attrs;
return create_thread(attrs, std::forward<Fn>(fn));
}
}
#endif // GUI_THREAD_HPP