TT#111051 set thread specific process names

Change-Id: I6a5bb14c070d93b865510786f5107220b93faef1
pull/1194/head
Richard Fuchs 5 years ago
parent 5c79036f63
commit a8013ffe70

@ -213,7 +213,7 @@ static void *thread_detach_func(void *d) {
return NULL; return NULL;
} }
static int thread_create(void *(*func)(void *), void *arg, int joinable, pthread_t *handle) { static int thread_create(void *(*func)(void *), void *arg, int joinable, pthread_t *handle, const char *name) {
pthread_attr_t att; pthread_attr_t att;
pthread_t thr; pthread_t thr;
int ret; int ret;
@ -235,11 +235,17 @@ static int thread_create(void *(*func)(void *), void *arg, int joinable, pthread
return ret; return ret;
if (handle) if (handle)
*handle = thr; *handle = thr;
#ifdef __GLIBC__
if (name)
pthread_setname_np(thr, name);
#endif
return 0; return 0;
} }
void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler, int priority) { void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler, int priority,
const char *name)
{
struct detach_thread *dt; struct detach_thread *dt;
dt = g_slice_alloc(sizeof(*dt)); dt = g_slice_alloc(sizeof(*dt));
@ -248,7 +254,7 @@ void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler
dt->scheduler = scheduler; dt->scheduler = scheduler;
dt->priority = priority; dt->priority = priority;
if (thread_create(thread_detach_func, dt, 1, NULL)) if (thread_create(thread_detach_func, dt, 1, NULL, name))
abort(); abort();
} }

@ -478,7 +478,7 @@ destroy:
if (xh) if (xh)
thread_create_detach_prio(xmlrpc_kill_calls, xh, rtpe_config.idle_scheduling, thread_create_detach_prio(xmlrpc_kill_calls, xh, rtpe_config.idle_scheduling,
rtpe_config.idle_priority); rtpe_config.idle_priority, "XMLRPC callback");
} }

@ -1059,39 +1059,44 @@ int main(int argc, char **argv) {
ilog(LOG_INFO, "Startup complete, version %s", RTPENGINE_VERSION); ilog(LOG_INFO, "Startup complete, version %s", RTPENGINE_VERSION);
thread_create_detach(sighandler, NULL); thread_create_detach(sighandler, NULL, "signal handler");
thread_create_detach_prio(poller_timer_loop, rtpe_poller, rtpe_config.idle_scheduling, rtpe_config.idle_priority); thread_create_detach_prio(poller_timer_loop, rtpe_poller, rtpe_config.idle_scheduling,
thread_create_detach_prio(load_thread, NULL, rtpe_config.idle_scheduling, rtpe_config.idle_priority); rtpe_config.idle_priority, "poller timer");
thread_create_detach_prio(load_thread, NULL, rtpe_config.idle_scheduling, rtpe_config.idle_priority, "load monitor");
if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && initial_rtpe_config.redis_delete_async) if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && initial_rtpe_config.redis_delete_async)
thread_create_detach(redis_delete_async_loop, NULL); thread_create_detach(redis_delete_async_loop, NULL, "redis async");
if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && rtpe_redis_notify) if (!is_addr_unspecified(&rtpe_config.redis_ep.address) && rtpe_redis_notify)
thread_create_detach(redis_notify_loop, NULL); thread_create_detach(redis_notify_loop, NULL, "redis notify");
if (!is_addr_unspecified(&rtpe_config.graphite_ep.address)) if (!is_addr_unspecified(&rtpe_config.graphite_ep.address))
thread_create_detach(graphite_loop, NULL); thread_create_detach(graphite_loop, NULL, "graphite");
thread_create_detach(ice_thread_run, NULL); thread_create_detach(ice_thread_run, NULL, "ICE");
websocket_start(); websocket_start();
service_notify("READY=1\n"); service_notify("READY=1\n");
for (idx = 0; idx < rtpe_config.num_threads; ++idx) for (idx = 0; idx < rtpe_config.num_threads; ++idx)
thread_create_detach_prio(poller_loop, rtpe_poller, rtpe_config.scheduling, rtpe_config.priority); thread_create_detach_prio(poller_loop, rtpe_poller, rtpe_config.scheduling,
rtpe_config.priority, "poller");
if (rtpe_config.media_num_threads < 0) if (rtpe_config.media_num_threads < 0)
rtpe_config.media_num_threads = rtpe_config.num_threads; rtpe_config.media_num_threads = rtpe_config.num_threads;
for (idx = 0; idx < rtpe_config.media_num_threads; ++idx) { for (idx = 0; idx < rtpe_config.media_num_threads; ++idx) {
#ifdef WITH_TRANSCODING #ifdef WITH_TRANSCODING
thread_create_detach_prio(media_player_loop, NULL, rtpe_config.scheduling, rtpe_config.priority); thread_create_detach_prio(media_player_loop, NULL, rtpe_config.scheduling,
rtpe_config.priority, "media player");
#endif #endif
thread_create_detach_prio(send_timer_loop, NULL, rtpe_config.scheduling, rtpe_config.priority); thread_create_detach_prio(send_timer_loop, NULL, rtpe_config.scheduling,
rtpe_config.priority, "send timer");
if (rtpe_config.jb_length > 0) if (rtpe_config.jb_length > 0)
thread_create_detach_prio(jitter_buffer_loop, NULL, rtpe_config.scheduling, thread_create_detach_prio(jitter_buffer_loop, NULL, rtpe_config.scheduling,
rtpe_config.priority); rtpe_config.priority, "jitter buffer");
thread_create_detach_prio(codec_timers_loop, NULL, rtpe_config.scheduling, rtpe_config.priority); thread_create_detach_prio(codec_timers_loop, NULL, rtpe_config.scheduling,
rtpe_config.priority, "codec timer");
} }

@ -953,5 +953,5 @@ static void websocket_loop(void *p) {
void websocket_start(void) { void websocket_start(void) {
if (!websocket_context) if (!websocket_context)
return; return;
thread_create_detach_prio(websocket_loop, NULL, rtpe_config.scheduling, rtpe_config.priority); thread_create_detach_prio(websocket_loop, NULL, rtpe_config.scheduling, rtpe_config.priority, "websocket");
} }

@ -278,9 +278,9 @@ taint_func(srandom, "use RAND_seed() instead");
/*** THREAD HELPERS ***/ /*** THREAD HELPERS ***/
void threads_join_all(int); void threads_join_all(int);
void thread_create_detach_prio(void (*)(void *), void *, const char *, int); void thread_create_detach_prio(void (*)(void *), void *, const char *, int, const char *);
INLINE void thread_create_detach(void (*f)(void *), void *a) { INLINE void thread_create_detach(void (*f)(void *), void *a, const char *name) {
thread_create_detach_prio(f, a, NULL, 0); thread_create_detach_prio(f, a, NULL, 0, name);
} }

Loading…
Cancel
Save