execution
1.0.1
Portable task execution, timers, and process lifecycle
Toggle main menu visibility
Loading...
Searching...
No Matches
set_current_thread_name.hpp
Go to the documentation of this file.
1
#ifndef STLAB_SET_CURRENT_THREAD_NAME_HPP
2
#define STLAB_SET_CURRENT_THREAD_NAME_HPP
3
7
8
#include <stlab/execution/config.hpp>
9
10
#if STLAB_THREADS(WIN32)
11
#include <cstring>
12
#include <string>
13
14
#include <windows.h>
15
16
#include <processthreadsapi.h>
17
#include <stringapiset.h>
18
#elif STLAB_THREADS(PTHREAD)
19
#include <pthread.h>
20
#elif STLAB_THREADS(PTHREAD_EMSCRIPTEN)
21
#include <pthread.h>
22
#include <emscripten/threading.h>
23
#elif STLAB_THREADS(PTHREAD_APPLE)
24
#include <pthread.h>
25
#elif STLAB_THREADS(NONE)
26
// Do nothing
27
#else
28
#error "Unspecified or unknown thread mode set."
29
#endif
30
31
namespace
stlab
{
32
38
39
inline
void
set_current_thread_name(
const
char
* name) {
40
#if STLAB_THREADS(WIN32)
41
/* Should string->wstring be split out to a utility? */
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
;
48
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)
57
// Nothing
58
#else
59
#error "Unspecified or unknown thread mode set."
60
#endif
61
}
62
64
65
}
// namespace stlab
66
67
#endif
stlab
Definition
default_executor.hpp:49
include
stlab
concurrency
set_current_thread_name.hpp
Generated by
1.18.0