5 #if defined(HAVE_CONFIG_H)
12 #if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
14 #include <pthread_np.h>
23 #ifdef HAVE_SYS_PRCTL_H
24 #include <sys/prctl.h>
29 static void SetThreadName(
const char*
name)
31 #if defined(PR_SET_NAME)
33 ::prctl(PR_SET_NAME,
name, 0, 0, 0);
34 #elif (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
35 pthread_set_name_np(pthread_self(),
name);
36 #elif defined(MAC_OSX)
37 pthread_setname_np(
name);
46 #if defined(HAVE_THREAD_LOCAL)
48 static thread_local std::string g_thread_name;
52 static void SetInternalName(std::string
name) { g_thread_name = std::move(
name); }
57 static const std::string empty_string;
59 static void SetInternalName(std::string
name) { }
64 SetThreadName((
"b-" +
name).c_str());
65 SetInternalName(std::move(
name));
70 SetInternalName(std::move(
name));
75 auto cond = std::make_shared<std::condition_variable>();
76 auto mutex = std::make_shared<std::mutex>();
77 std::atomic<int> doneCnt(0);
78 for (
int i = 0; i < tp.
size(); i++) {
79 tp.
push([baseName, i, cond, mutex, &doneCnt](
int threadId) {
82 std::unique_lock<std::mutex> l(*mutex);
86 while (doneCnt != tp.
size()) {
auto push(F &&f, Rest &&... rest) -> std::future< decltype(f(0, rest...))>
void ThreadSetInternalName(std::string &&)
Set the internal (in-memory) name of the current thread only.
const std::string & ThreadGetInternalName()
Get the thread's internal (in-memory) name; used e.g.
void ThreadRename(std::string &&)
Rename a thread both in terms of an internal (in-memory) name as well as its system thread name.
void RenameThreadPool(ctpl::thread_pool &tp, const char *baseName)
void MilliSleep(int64_t n)