From e0d6dd8f3c12fa096030cedcde8dc703b4f7787e Mon Sep 17 00:00:00 2001 From: Syrone Wong Date: Fri, 30 Sep 2016 18:33:26 -0500 Subject: [PATCH] libcork: use API where supported (#860) - The usage of `pthread_setname_np` is not supported on versions of glibc earlier than 2.12. This patch checks the glibc MINOR version and only uses that API where supported. - This will suppress undeclared function warning when compiling with uClibc/musl-libc. Signed-off-by: Syrone Wong --- libcork/pthreads/thread.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libcork/pthreads/thread.c b/libcork/pthreads/thread.c index 002416e1..d8347790 100644 --- a/libcork/pthreads/thread.c +++ b/libcork/pthreads/thread.c @@ -169,7 +169,7 @@ cork_thread_start(struct cork_thread *self) { int rc; pthread_t thread_id; -#if defined(__linux) +#if defined(__linux) && ((__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 12)) char thread_name[PTHREADS_MAX_THREAD_NAME_LENGTH]; #endif @@ -181,8 +181,11 @@ cork_thread_start(struct cork_thread *self) return -1; } -#if defined(__linux) - /* On Linux we choose which thread to name via an explicit thread ID. */ +#if defined(__linux) && ((__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 12)) + /* On Linux we choose which thread to name via an explicit thread ID. + * However, pthread_setname_np() isn't supported on versions of glibc + * earlier than 2.12. So we need to check for a MINOR version of 12 or + * higher. */ strncpy(thread_name, self->name, PTHREADS_MAX_THREAD_NAME_LENGTH); thread_name[PTHREADS_MAX_THREAD_NAME_LENGTH - 1] = '\0'; pthread_setname_np(thread_id, thread_name);