mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-20 01:50:26 -05:00
Merge branch 'bradkeifer-master'
This commit is contained in:
28
configure.ac
28
configure.ac
@@ -75,25 +75,33 @@ AC_SEARCH_LIBS([timer_settime], [rt],
|
||||
AC_SEARCH_LIBS([pthread_exit], [pthread], [],
|
||||
[AC_MSG_ERROR([[pthreads library is required]])])
|
||||
AC_SEARCH_LIBS([pthread_setname_np], [pthread],
|
||||
[dnl Validate pthread_setname_np with 2 args (some have 1)
|
||||
AC_MSG_CHECKING([[for two-parameter pthread_setname_np]])
|
||||
[AC_MSG_CHECKING([[for two-parameter pthread_setname_np]])
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <pthread.h>]],
|
||||
[[pthread_setname_np(pthread_self(), "name");]])],
|
||||
[AC_MSG_RESULT([yes])
|
||||
AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], 1,
|
||||
[Define to 1 if you have pthread_setname_np])],
|
||||
[AC_MSG_RESULT([[no]])])],
|
||||
[AC_SEARCH_LIBS([pthread_set_name_np], [pthread],
|
||||
[AC_CHECK_FUNCS([pthread_set_name_np])])])
|
||||
[Define to 1 if you have pthread_setname_np with 2 args])],
|
||||
[AC_MSG_RESULT([[no]])])
|
||||
AC_MSG_CHECKING([[for MacOS single-parameter pthread_setname_np]])
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[@%:@include <pthread.h>]],
|
||||
[[pthread_setname_np("name");]])],
|
||||
[AC_MSG_RESULT([yes])
|
||||
AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_MACOS], 1,
|
||||
[Define to 1 if you have pthread_setname_np with 1 arg])],
|
||||
[AC_MSG_RESULT([[no]])])])
|
||||
AC_SEARCH_LIBS([pthread_set_name_np], [pthread],
|
||||
[AC_DEFINE([HAVE_PTHREAD_SET_NAME_NP], 1,
|
||||
[Define to 1 if you have pthread_set_name_np])])
|
||||
AC_SEARCH_LIBS([pthread_getname_np], [pthread],
|
||||
[AC_DEFINE([HAVE_PTHREAD_GETNAME_NP], 1,
|
||||
[Define to 1 if you have pthread_getname_np])]
|
||||
[AC_SEARCH_LIBS([pthread_get_name_np], [pthread],
|
||||
[AC_DEFINE([HAVE_PTHREAD_GETNAME_NP], 1,
|
||||
[Define to 1 if you have pthread_get_name_np])])])
|
||||
[Define to 1 if you have pthread_getname_np])])
|
||||
AC_SEARCH_LIBS([pthread_get_name_np], [pthread],
|
||||
[AC_DEFINE([HAVE_PTHREAD_GET_NAME_NP], 1,
|
||||
[Define to 1 if you have pthread_get_name_np])])
|
||||
AC_SEARCH_LIBS([pthread_getthreadid_np], [pthread],
|
||||
[AC_DEFINE([HAVE_PTHREAD_GETTHREADID_NP], 1,
|
||||
[Define to 1 if you have pthread_getthreadid_np])])
|
||||
|
||||
AC_SEARCH_LIBS([uuid_generate_random], [uuid],
|
||||
[AC_DEFINE([HAVE_UUID], 1,
|
||||
[Define to 1 if you have uuid_generate_random])])
|
||||
|
||||
@@ -1690,6 +1690,8 @@ cache(void *arg)
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
thread_setname("cache");
|
||||
|
||||
ret = cache_open();
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -2062,7 +2064,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");
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <event2/thread.h>
|
||||
|
||||
#include "evthr.h"
|
||||
#include "misc.h"
|
||||
|
||||
#ifndef TAILQ_FOREACH_SAFE
|
||||
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
|
||||
@@ -135,6 +136,8 @@ _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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -817,6 +817,8 @@ 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 +936,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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
26
src/misc.c
26
src/misc.c
@@ -1853,26 +1853,29 @@ mutex_init(pthread_mutex_t *mutex)
|
||||
}
|
||||
|
||||
int
|
||||
thread_gettid()
|
||||
thread_gettid(void)
|
||||
{
|
||||
int tid = -1;
|
||||
int tid;
|
||||
#if defined(HAVE_GETTID)
|
||||
tid = (int)gettid();
|
||||
#elif defined(HAVE_PTHREAD_GETTHREADID_NP)
|
||||
tid = pthread_getthreadid_np();
|
||||
#else //defacto thread id
|
||||
tid = (int)pthread_self();
|
||||
#endif
|
||||
return tid;
|
||||
}
|
||||
|
||||
void
|
||||
thread_getname(pthread_t thread, char *name, size_t len)
|
||||
thread_getname(char *name, size_t len)
|
||||
{
|
||||
#if defined(HAVE_PTHREAD_GETNAME_NP)
|
||||
pthread_getname_np(thread, name, len);
|
||||
pthread_getname_np(pthread_self(), name, len);
|
||||
#elif defined(HAVE_PTHREAD_GET_NAME_NP)
|
||||
pthread_get_name_np(thread, name, len);
|
||||
pthread_get_name_np(pthread_self(), name, len);
|
||||
#else
|
||||
name[0] = '\0';
|
||||
if (len > 0)
|
||||
name[0] = '\0';
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1881,20 +1884,21 @@ thread_getnametid(char *buf, size_t len)
|
||||
{
|
||||
int tid;
|
||||
char thread_name[32];
|
||||
pthread_t p = pthread_self();
|
||||
|
||||
thread_getname(p, thread_name, sizeof(thread_name));
|
||||
thread_getname(thread_name, sizeof(thread_name));
|
||||
tid = thread_gettid() % 10000;
|
||||
snprintf(buf, len, "%s (%d)", thread_name, tid);
|
||||
}
|
||||
|
||||
void
|
||||
thread_setname(pthread_t thread, const char *name)
|
||||
thread_setname(const char *name)
|
||||
{
|
||||
#if defined(HAVE_PTHREAD_SETNAME_NP)
|
||||
pthread_setname_np(thread, name);
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
#elif defined(HAVE_PTHREAD_SETNAME_NP_MACOS)
|
||||
pthread_setname_np(name);
|
||||
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
|
||||
pthread_set_name_np(thread, name);
|
||||
pthread_set_name_np(pthread_self(), name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -318,20 +318,19 @@ buildopts_get(void);
|
||||
int
|
||||
mutex_init(pthread_mutex_t *mutex);
|
||||
|
||||
// wrapper for gettid/pthread_getthreadid_np
|
||||
int
|
||||
thread_gettid();
|
||||
thread_gettid(void);
|
||||
|
||||
// wrapper for pthread_getname_np/pthread_get_name_np
|
||||
void
|
||||
thread_getname(pthread_t thread, char *name, size_t len);
|
||||
thread_getname(char *name, size_t len);
|
||||
|
||||
void
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -470,6 +470,9 @@ 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 +522,6 @@ airplay_events_init(void)
|
||||
goto error;
|
||||
}
|
||||
|
||||
// TODO thread_name_set(thread_id, "airplay events");
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -415,6 +415,8 @@ 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 +535,6 @@ websocket_init(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
thread_setname(tid_websocket, "websocket");
|
||||
|
||||
websocket_is_initialized = true;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -100,7 +100,7 @@ init_cb(struct evthr *thr, void *shared)
|
||||
|
||||
worker_thr = thr;
|
||||
|
||||
thread_setname(pthread_self(), "worker");
|
||||
thread_setname("worker");
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user