thread/Name: enable FormatThreadName() with prctl()

Add macro HAVE_THREAD_NAME which is set when any method to set the
thread name is available.  Use that macro in FormatThreadName()
instead of just checking for HAVE_PTHREAD_SETNAME_NP.
This commit is contained in:
Max Kellermann 2015-01-06 12:04:02 +01:00
parent 11cea17496
commit b9ed850b98

View File

@ -21,10 +21,14 @@
#define MPD_THREAD_NAME_HXX #define MPD_THREAD_NAME_HXX
#ifdef HAVE_PTHREAD_SETNAME_NP #ifdef HAVE_PTHREAD_SETNAME_NP
# define HAVE_THREAD_NAME
# include <pthread.h> # include <pthread.h>
# include <stdio.h> # include <stdio.h>
#elif defined(HAVE_PRCTL) #elif defined(HAVE_PRCTL)
# include <sys/prctl.h> # include <sys/prctl.h>
# ifdef PR_SET_NAME
# define HAVE_THREAD_NAME
# endif
#endif #endif
static inline void static inline void
@ -47,7 +51,7 @@ template<typename... Args>
static inline void static inline void
FormatThreadName(const char *fmt, gcc_unused Args&&... args) FormatThreadName(const char *fmt, gcc_unused Args&&... args)
{ {
#ifdef HAVE_PTHREAD_SETNAME_NP #ifdef HAVE_THREAD_NAME
char buffer[16]; char buffer[16];
snprintf(buffer, sizeof(buffer), fmt, args...); snprintf(buffer, sizeof(buffer), fmt, args...);
SetThreadName(buffer); SetThreadName(buffer);