[misc] PR #1941 adjustments

This commit is contained in:
ejurgensen
2025-11-11 23:19:05 +01:00
parent 38e1c89908
commit ec66f95269
8 changed files with 39 additions and 43 deletions

View File

@@ -75,33 +75,29 @@ 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_2], 1,
AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], 1,
[Define to 1 if you have pthread_setname_np with 2 args])],
[AC_MSG_RESULT([[no]])])],
[AC_SEARCH_LIBS([pthread_set_name_np], [pthread],
[AC_CHECK_FUNCS([pthread_set_name_np])])])
AC_SEARCH_LIBS([pthread_setname_np], [pthread],
[dnl Validate pthread_setname_np with 1 arg (some have 2)
AC_MSG_CHECKING([[for single-parameter pthread_setname_np]])
[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_1], 1,
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_CHECK_FUNCS([pthread_set_name_np])])])
[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])])

View File

@@ -1691,6 +1691,7 @@ cache(void *arg)
int i;
thread_setname("cache");
ret = cache_open();
if (ret < 0)
{

View File

@@ -137,6 +137,7 @@ _evthr_loop(void *args)
}
thread_setname("evthr");
thread->evbase = event_base_new();
thread->event = event_new(thread->evbase, thread->rdr,
EV_READ | EV_PERSIST, _evthr_read_cmd, args);

View File

@@ -818,6 +818,7 @@ static void *
pipe_thread_run(void *arg)
{
thread_setname("pipe");
event_base_dispatch(evbase_pipe);
pthread_exit(NULL);

View File

@@ -1852,55 +1852,51 @@ mutex_init(pthread_mutex_t *mutex)
return err;
}
int64_t
thread_gettid(pthread_t p)
int
thread_gettid(void)
{
int64_t tid = -1;
int tid;
#if defined(HAVE_GETTID)
tid = (int64_t)gettid();
tid = (int)gettid();
#elif defined(HAVE_PTHREAD_GETTHREADID_NP)
tid = (int64_t)pthread_getthreadid_np();
tid = pthread_getthreadid_np();
#else //defacto thread id
tid = (int64_t)p;
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
}
void
thread_getnametid(char *buf, size_t len)
{
int64_t tid;
int tid;
char thread_name[32];
pthread_t p = pthread_self();
thread_getname(p, thread_name, sizeof(thread_name));
tid = thread_gettid(p) % 10000;
snprintf(buf, len, "%s (%" PRId64 ")", thread_name, tid);
thread_getname(thread_name, sizeof(thread_name));
tid = thread_gettid() % 10000;
snprintf(buf, len, "%s (%d)", thread_name, tid);
}
void
thread_setname(const char *name)
{
#if defined(HAVE_PTHREAD_SETNAME_NP_1)
pthread_setname_np(name);
DPRINTF(E_DBG, L_MISC,
"%s: Single argument pthread_setname_np(%s). Be aware! It must be called from thread whose name is to be changed\n",
__func__, name
);
#elif defined(HAVE_PTHREAD_SETNAME_NP_2)
#if defined(HAVE_PTHREAD_SETNAME_NP)
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(pthread_self(), name);
#endif

View File

@@ -318,13 +318,12 @@ buildopts_get(void);
int
mutex_init(pthread_mutex_t *mutex);
// wrapper for gettid/pthread_getthreadid_np
int64_t
thread_gettid(pthread_t p);
int
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);

View File

@@ -472,6 +472,7 @@ airplay_events(void *arg)
{
thread_setname("airplay events");
event_base_dispatch(evbase);
pthread_exit(NULL);

View File

@@ -416,6 +416,7 @@ 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);