Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -548,10 +548,14 @@ AC_CHECK_FUNC(sched_yield, [ AC_DEFINE(OF_HAVE_SCHED_YIELD, 1, [Whether we have sched_yield()]) ]) + + AC_CHECK_HEADERS(pthread_np.h) + AC_CHECK_FUNCS(pthread_set_name_np pthread_setname_np, + break) ], [ AC_MSG_ERROR(No supported threads found!) ]) ;; esac Index: src/threading.m ================================================================== --- src/threading.m +++ src/threading.m @@ -28,18 +28,10 @@ #ifdef __HAIKU__ # include #endif -void -of_thread_set_name(of_thread_t thread, const char *name) -{ -#ifdef __HAIKU__ - rename_thread(get_pthread_thread_id(thread), name); -#endif -} - bool of_rmutex_new(of_rmutex_t *rmutex) { #ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES pthread_mutexattr_t attr; Index: src/threading_pthread.m ================================================================== --- src/threading_pthread.m +++ src/threading_pthread.m @@ -11,10 +11,14 @@ * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ + +#ifdef HAVE_PTHREAD_NP_H +# include +#endif struct thread_ctx { void (*function)(id object); id object; }; @@ -151,10 +155,31 @@ { pthread_exit(NULL); OF_UNREACHABLE } + +void +of_thread_set_name(of_thread_t thread, const char *name) +{ +#if defined(__HAIKU__) + rename_thread(get_pthread_thread_id(thread), name); +#elif defined(HAVE_PTHREAD_SET_NAME_NP) + pthread_set_name_np(pthread_self(), name); +#elif defined(HAVE_PTHREAD_SETNAME_NP) +# if defined(__APPLE__) + pthread_setname_np(name); +# elif defined(__GLIBC__) + char buffer[16]; + + strncpy(buffer, name, 15); + buffer[15] = 0; + + pthread_setname_np(pthread_self(), buffer); +# endif +#endif +} void of_once(of_once_t *control, void (*func)(void)) { pthread_once(control, func); Index: src/threading_winapi.m ================================================================== --- src/threading_winapi.m +++ src/threading_winapi.m @@ -76,10 +76,15 @@ { ExitThread(0); OF_UNREACHABLE } + +void +of_thread_set_name(of_thread_t thread, const char *name) +{ +} void of_once(of_once_t *control, void (*func)(void)) { switch (InterlockedCompareExchange(control, 1, 0)) {