From 6256946dee9ac9c7da85e10405ab754aafdb8253 Mon Sep 17 00:00:00 2001 From: Steven Chamberlain Date: Wed, 13 Jul 2016 14:48:02 +0100 Subject: [PATCH] bx: further refactor #ifdefs Trying to evaluate __GLIBC__ will result in an error if is not defined, if the preprocessor does not short-cut the evaluation. Split the macros onto separate lines and define the result in a new BX_USE_GLIBC_PTHREAD_SETNAME_NP macro to avoid duplication. --- 3rdparty/bx/include/bx/thread.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/3rdparty/bx/include/bx/thread.h b/3rdparty/bx/include/bx/thread.h index bd74f66f4e3..268ca779dfa 100644 --- a/3rdparty/bx/include/bx/thread.h +++ b/3rdparty/bx/include/bx/thread.h @@ -6,12 +6,19 @@ #ifndef BX_THREAD_H_HEADER_GUARD #define BX_THREAD_H_HEADER_GUARD +#define BX_USE_GLIBC_PTHREAD_SETNAME_NP 0 +#if defined(__GLIBC__) +# if ( (__GLIBC__ > 2) || ( (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12) ) ) +# define BX_USE_GLIBC_PTHREAD_SETNAME_NP 1 +# endif +#endif + #if BX_PLATFORM_POSIX # include -# if defined(__GLIBC__) -# if !( (__GLIBC__ > 2) || ( (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12) ) ) -# include -# endif +# if BX_USE_GLIBC_PTHREAD_SETNAME_NP +/* pthread.h provides pthread_setname_np */ +# elif defined(BX_PLATFORM_LINUX) +# include # elif defined(BX_PLATFORM_BSD) # include # endif @@ -158,7 +165,7 @@ namespace bx { #if BX_PLATFORM_OSX || BX_PLATFORM_IOS pthread_setname_np(_name); -#elif defined(__GLIBC__) && (__GLIBC__ > 2) || ( (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12) ) +#elif BX_USE_GLIBC_PTHREAD_SETNAME_NP pthread_setname_np(m_handle, _name); #elif BX_PLATFORM_LINUX prctl(PR_SET_NAME,_name, 0, 0, 0);