UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
thread.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void set_thread_name (const char *name)
 

Detailed Description

Function Documentation

◆ set_thread_name()

void set_thread_name ( const char * name)

Definition at line 72 of file thread.c.

72 {
73#ifdef __linux__
74// thread name can have at most 16 chars (including terminating null char)
75 char *prog_name = get_argv_program_name();
76 char tmp[16];
77 tmp[sizeof tmp - 1] = '\0';
78 strncpy(tmp, prog_name, sizeof tmp - 1);
79 free(prog_name);
80 strncat(tmp, name, sizeof tmp - strlen(tmp) - 1);
81 pthread_setname_np(pthread_self(), tmp);
82#elif defined __APPLE__
83 char *prog_name = get_argv_program_name();
84 char *tmp = (char *) alloca(strlen(prog_name) + strlen(name) + 1);
85 strcpy(tmp, prog_name);
86 free(prog_name);
87 strcat(tmp, name);
88 pthread_setname_np(tmp);
89#elif defined _WIN32
90// supported from Windows 10, not yet in headers
91#ifdef HAVE_SETTHREADDESCRIPTION
92 const char *prog_name = get_argv_program_name();
93 size_t dst_len = (mbstowcs(NULL, prog_name, 0) + mbstowcs(NULL, name, 0) + 1) * sizeof(wchar_t);
94 wchar_t *tmp = (wchar_t *) alloca(dst_len);
95 mbstowcs(tmp, prog_name, dst_len / sizeof(wchar_t));
96 mbstowcs(tmp + wcslen(tmp), name, dst_len / sizeof(wchar_t) - wcslen(tmp));
97 SetThreadDescription(GetCurrentThread(), tmp);
98#else
99 UNUSED(name);
100#endif
101#endif
102}
#define UNUSED(x)
const char * name
Definition settings.cpp:193
static char * get_argv_program_name(void)
Definition thread.c:57

References get_argv_program_name(), name, and UNUSED.

Referenced by audio_receiver_thread(), audio_sender_thread(), capture_thread(), control_thread(), decompress_thread(), display_run_helper(), wp_worker::enter_loop(), fec_thread(), loopback_video_rxtx::receiver_loop(), ultragrid_rtp_video_rxtx::receiver_loop(), keyboard_control::impl::run(), video_rxtx::sender_loop(), state_root::should_exit_watcher(), stat_event_thread(), udp_reader(), vidcap_file_worker(), vidcap_testcard2_thread(), and state_audio_mixer::worker().

Here is the call graph for this function: