[misc] Centralize thread naming plus name websocket thread

This commit is contained in:
ejurgensen 2021-07-05 21:40:31 +02:00
parent eae09039d5
commit d2f4efa1bf
13 changed files with 33 additions and 83 deletions

View File

@ -30,9 +30,6 @@
#include <time.h>
#include <string.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include <event2/event.h>
#include <sqlite3.h>
@ -1640,11 +1637,7 @@ cache_init(void)
goto thread_fail;
}
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(tid_cache, "cache");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(tid_cache, "cache");
#endif
thread_setname(tid_cache, "cache");
return 0;

View File

@ -28,9 +28,6 @@
#include <limits.h>
#include <errno.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include <time.h>
#include <sys/param.h>
#include <sys/queue.h>
@ -1789,11 +1786,7 @@ httpd_init(const char *webroot)
goto thread_fail;
}
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(tid_httpd, "httpd");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(tid_httpd, "httpd");
#endif
thread_setname(tid_httpd, "httpd");
return 0;

View File

@ -32,9 +32,6 @@
#include <event2/event.h>
#include <event2/buffer.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include "misc.h"
#include "logger.h"
@ -927,11 +924,7 @@ input_init(void)
goto thread_fail;
}
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(tid_input, "input");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(tid_input, "input");
#endif
thread_setname(tid_input, "input");
return 0;

View File

@ -35,9 +35,6 @@
#include <sys/ioctl.h>
#include <sys/queue.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include <dlfcn.h>
#include <libspotify/api.h>
@ -1575,11 +1572,7 @@ libspotify_init(void)
goto thread_fail;
}
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(tid_spotify, "spotify");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(tid_spotify, "spotify");
#endif
thread_setname(tid_spotify, "spotify");
DPRINTF(E_DBG, L_SPOTIFY, "Spotify init complete\n");
return 0;

View File

@ -45,9 +45,6 @@
#include <errno.h>
#include <limits.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
@ -854,11 +851,7 @@ pipe_thread_start(void)
CHECK_NULL(L_PLAYER, cmdbase = commands_base_new(evbase_pipe, NULL));
CHECK_ERR(L_PLAYER, pthread_create(&tid_pipe, NULL, pipe_thread_run, NULL));
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(tid_pipe, "pipe");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(tid_pipe, "pipe");
#endif
thread_setname(tid_pipe, "pipe");
}
static void

View File

@ -24,9 +24,6 @@
#include <stdint.h>
#include <fcntl.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include <event2/event.h>
@ -229,11 +226,7 @@ tcp_disconnect(int fd)
static void
thread_name_set(pthread_t thread)
{
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(thread, "spotify");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(thread, "spotify");
#endif
thread_setname(thread, "spotify");
}
static void

View File

@ -26,9 +26,6 @@
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
@ -882,11 +879,7 @@ library_init(void)
CHECK_ERR(L_LIB, pthread_create(&tid_library, NULL, library, NULL));
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(tid_library, "library");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(tid_library, "library");
#endif
thread_setname(tid_library, "library");
return 0;
}

View File

@ -44,6 +44,9 @@
#ifdef HAVE_UUID
#include <uuid/uuid.h>
#endif
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include <netdb.h>
#include <arpa/inet.h>
@ -1545,6 +1548,16 @@ mutex_init(pthread_mutex_t *mutex)
return err;
}
void
thread_setname(pthread_t thread, const char *name)
{
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(thread, name);
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(thread, name);
#endif
}
#ifdef HAVE_UUID
void
uuid_make(char *str)

View File

@ -284,6 +284,10 @@ buildopts_get(void);
int
mutex_init(pthread_mutex_t *mutex);
// wrapper for pthread_setname_np/pthread_set_name_np
void
thread_setname(pthread_t thread, const char *name);
void
uuid_make(char *str);

View File

@ -29,9 +29,6 @@
#include <limits.h>
#include <errno.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
@ -4846,11 +4843,7 @@ mpd_init(void)
goto thread_fail;
}
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(tid_mpd, "mpd");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(tid_mpd, "mpd");
#endif
thread_setname(tid_mpd, "mpd");
mpd_clients = NULL;
listener_add(mpd_listener_cb, MPD_ALL_IDLE_LISTENER_EVENTS);

View File

@ -59,9 +59,6 @@
#include <errno.h>
#include <time.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#ifdef HAVE_TIMERFD
# include <sys/timerfd.h>
@ -3708,11 +3705,8 @@ player_init(void)
DPRINTF(E_FATAL, L_PLAYER, "Could not spawn player thread: %s\n", strerror(errno));
goto error_input_deinit;
}
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(tid_player, "player");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(tid_player, "player");
#endif
thread_setname(tid_player, "player");
return 0;

View File

@ -19,12 +19,10 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <json.h>
#include <libwebsockets.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
@ -34,6 +32,7 @@
#include "conffile.h"
#include "listener.h"
#include "logger.h"
#include "misc.h"
static struct lws_context *context;
@ -523,6 +522,8 @@ websocket_init(void)
return -1;
}
thread_setname(tid_websocket, "websocket");
return 0;
}

View File

@ -30,9 +30,6 @@
#include <string.h>
#include <errno.h>
#include <pthread.h>
#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif
#include <event2/event.h>
@ -40,6 +37,7 @@
#include "logger.h"
#include "worker.h"
#include "commands.h"
#include "misc.h"
struct worker_arg
@ -191,11 +189,7 @@ worker_init(void)
goto thread_fail;
}
#if defined(HAVE_PTHREAD_SETNAME_NP)
pthread_setname_np(tid_worker, "worker");
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(tid_worker, "worker");
#endif
thread_setname(tid_worker, "worker");
return 0;