diff --git a/src/cache.c b/src/cache.c index 21642d8c..0c66c8c3 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1690,6 +1690,7 @@ cache(void *arg) int ret; int i; + thread_setname("cache"); ret = cache_open(); if (ret < 0) { @@ -2062,7 +2063,6 @@ cache_init(void) CHECK_NULL(L_CACHE, cmdbase = commands_base_new(evbase_cache, NULL)); CHECK_ERR(L_CACHE, pthread_create(&tid_cache, NULL, cache, NULL)); - thread_setname(tid_cache, "cache"); DPRINTF(E_INFO, L_CACHE, "Cache thread init\n"); diff --git a/src/evthr.c b/src/evthr.c index 0c236cdc..559f72f0 100644 --- a/src/evthr.c +++ b/src/evthr.c @@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include "evthr.h" +#include "misc.h" #ifndef TAILQ_FOREACH_SAFE #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ @@ -135,6 +136,7 @@ _evthr_loop(void *args) pthread_exit(NULL); } + thread_setname("evthr"); thread->evbase = event_base_new(); thread->event = event_new(thread->evbase, thread->rdr, EV_READ | EV_PERSIST, _evthr_read_cmd, args); diff --git a/src/httpd.c b/src/httpd.c index ae421b97..963994a6 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -1538,7 +1538,7 @@ thread_init_cb(struct evthr *thr, void *shared) struct event_base *evbase; httpd_server *server; - thread_setname(pthread_self(), "httpd"); + thread_setname("httpd"); CHECK_ERR(L_HTTPD, db_perthread_init()); CHECK_NULL(L_HTTPD, evbase = evthr_get_base(thr)); diff --git a/src/input.c b/src/input.c index 5d7dbba4..14cd4ea2 100644 --- a/src/input.c +++ b/src/input.c @@ -656,6 +656,8 @@ input(void *arg) { int ret; + thread_setname("input"); + ret = db_perthread_init(); if (ret < 0) { @@ -932,8 +934,6 @@ input_init(void) goto thread_fail; } - thread_setname(tid_input, "input"); - return 0; thread_fail: diff --git a/src/inputs/pipe.c b/src/inputs/pipe.c index 21d3800a..5648923b 100644 --- a/src/inputs/pipe.c +++ b/src/inputs/pipe.c @@ -817,6 +817,7 @@ pipe_watch_update(void *arg, int *retval) static void * pipe_thread_run(void *arg) { + thread_setname("pipe"); event_base_dispatch(evbase_pipe); pthread_exit(NULL); @@ -934,8 +935,6 @@ pipe_thread_start(void) CHECK_NULL(L_PLAYER, evbase_pipe = event_base_new()); CHECK_NULL(L_PLAYER, cmdbase = commands_base_new(evbase_pipe, NULL)); CHECK_ERR(L_PLAYER, pthread_create(&tid_pipe, NULL, pipe_thread_run, NULL)); - - thread_setname(tid_pipe, "pipe"); } static void diff --git a/src/inputs/spotify_librespotc.c b/src/inputs/spotify_librespotc.c index c7c5a2fa..c6cb46b6 100644 --- a/src/inputs/spotify_librespotc.c +++ b/src/inputs/spotify_librespotc.c @@ -240,7 +240,7 @@ tcp_disconnect(int fd) static void thread_name_set(pthread_t thread) { - thread_setname(thread, "spotify"); + thread_setname("spotify"); } static void diff --git a/src/library.c b/src/library.c index a21f22e5..2467cdde 100644 --- a/src/library.c +++ b/src/library.c @@ -1005,6 +1005,8 @@ library(void *arg) { int ret; + thread_setname("library"); + #ifdef __linux__ struct sched_param param; @@ -1074,8 +1076,6 @@ library_init(void) CHECK_ERR(L_LIB, pthread_create(&tid_library, NULL, library, NULL)); - thread_setname(tid_library, "library"); - return 0; } diff --git a/src/misc.c b/src/misc.c index 8f0b9263..4cfe45e9 100644 --- a/src/misc.c +++ b/src/misc.c @@ -1891,7 +1891,7 @@ thread_getnametid(char *buf, size_t len) } void -thread_setname(pthread_t thread, const char *name) +thread_setname(const char *name) { #if defined(HAVE_PTHREAD_SETNAME_NP_1) pthread_setname_np(name); @@ -1900,9 +1900,9 @@ thread_setname(pthread_t thread, const char *name) __func__, name ); #elif defined(HAVE_PTHREAD_SETNAME_NP_2) - pthread_setname_np(thread, name); + pthread_setname_np(pthread_self(), name); #elif defined(HAVE_PTHREAD_SET_NAME_NP) - pthread_set_name_np(thread, name); + pthread_set_name_np(pthread_self(), name); #endif } diff --git a/src/misc.h b/src/misc.h index dce0eda7..ca4bbfb9 100644 --- a/src/misc.h +++ b/src/misc.h @@ -331,7 +331,7 @@ thread_getnametid(char *buf, size_t len); // wrapper for pthread_setname_np/pthread_set_name_np void -thread_setname(pthread_t thread, const char *name); +thread_setname(const char *name); void uuid_make(char *str); diff --git a/src/mpd.c b/src/mpd.c index bd0f6a92..b2a8b3d0 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -4242,6 +4242,8 @@ mpd(void *arg) { int ret; + thread_setname("mpd"); + ret = db_perthread_init(); if (ret < 0) { @@ -4370,8 +4372,6 @@ mpd_init(void) goto thread_fail; } - thread_setname(tid_mpd, "mpd"); - mpd_clients = NULL; listener_add(mpd_listener_cb, MPD_ALL_IDLE_LISTENER_EVENTS, NULL); diff --git a/src/outputs/airplay_events.c b/src/outputs/airplay_events.c index 7a6f77f6..d3e657e2 100644 --- a/src/outputs/airplay_events.c +++ b/src/outputs/airplay_events.c @@ -470,6 +470,8 @@ incoming_cb(int fd, short what, void *arg) static void * airplay_events(void *arg) { + + thread_setname("airplay events"); event_base_dispatch(evbase); pthread_exit(NULL); @@ -519,8 +521,6 @@ airplay_events_init(void) goto error; } -// TODO thread_name_set(thread_id, "airplay events"); - return 0; error: diff --git a/src/player.c b/src/player.c index 8b77c254..d1053e42 100644 --- a/src/player.c +++ b/src/player.c @@ -3839,6 +3839,8 @@ player(void *arg) struct output_device *device; int ret; + thread_setname("player"); + ret = db_perthread_init(); if (ret < 0) { @@ -3954,8 +3956,6 @@ player_init(void) goto error_input_deinit; } - thread_setname(tid_player, "player"); - return 0; error_input_deinit: diff --git a/src/websocket.c b/src/websocket.c index ca259b48..c1b15a9f 100644 --- a/src/websocket.c +++ b/src/websocket.c @@ -415,6 +415,7 @@ static struct lws_protocols protocols[] = static void * websocket(void *arg) { + thread_setname("websocket"); listener_add(listener_cb, LISTENER_UPDATE | LISTENER_DATABASE | LISTENER_PAIRING | LISTENER_SPOTIFY | LISTENER_LASTFM | LISTENER_SPEAKER | LISTENER_PLAYER | LISTENER_OPTIONS | LISTENER_VOLUME | LISTENER_QUEUE, NULL); @@ -533,8 +534,6 @@ websocket_init(void) return -1; } - thread_setname(tid_websocket, "websocket"); - websocket_is_initialized = true; return 0; diff --git a/src/worker.c b/src/worker.c index ecbc9836..01161443 100644 --- a/src/worker.c +++ b/src/worker.c @@ -100,7 +100,7 @@ init_cb(struct evthr *thr, void *shared) worker_thr = thr; - thread_setname(pthread_self(), "worker"); + thread_setname("worker"); } static void