1#ifndef STLAB_SET_CURRENT_THREAD_NAME_HPP
2#define STLAB_SET_CURRENT_THREAD_NAME_HPP
8#include <stlab/config.hpp>
10#if STLAB_THREADS(WIN32)
16 #include <processthreadsapi.h>
17 #include <stringapiset.h>
18#elif STLAB_THREADS(PTHREAD)
20#elif STLAB_THREADS(PTHREAD_EMSCRIPTEN)
22 #include <emscripten/threading.h>
23#elif STLAB_THREADS(PTHREAD_APPLE)
25#elif STLAB_THREADS(NONE)
28 #error "Unspecified or unknown thread mode set."
39inline void set_current_thread_name(
const char* name) {
40#if STLAB_THREADS(WIN32)
42 int count = MultiByteToWideChar(CP_UTF8, 0, name,
static_cast<int>(std::strlen(name)), NULL, 0);
43 if (count <= 0)
return;
44 std::wstring str(count,
wchar_t{});
45 count = MultiByteToWideChar(CP_UTF8, 0, name,
static_cast<int>(std::strlen(name)), &str[0],
46 static_cast<int>(str.size()));
47 if (count <= 0)
return;
49 (void)SetThreadDescription(GetCurrentThread(), str.c_str());
50#elif STLAB_THREADS(PTHREAD_EMSCRIPTEN)
51 emscripten_set_thread_name(pthread_self(), name);
52#elif STLAB_THREADS(PTHREAD_APPLE)
53 pthread_setname_np(name);
54#elif STLAB_THREADS(PTHREAD)
55 pthread_setname_np(pthread_self(), name);
56#elif STLAB_THREADS(NONE)
59 #error "Unspecified or unknown thread mode set."
Definition reverse.hpp:28