Detect availability of pthread_setname_np and pthread_set_name_np

This commit is contained in:
Cameron Cawley
2024-08-29 20:07:30 +00:00
committed by Ronald S. Bultje
co-authored by Ronald S. Bultje
parent ccb02ddf8d
commit 033a090923
2 changed files with 28 additions and 15 deletions
+6
View File
@@ -259,6 +259,12 @@ endif
if cc.has_function('pthread_setaffinity_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency)
cdata.set('HAVE_PTHREAD_SETAFFINITY_NP', 1)
endif
if cc.has_function('pthread_setname_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency)
cdata.set('HAVE_PTHREAD_SETNAME_NP', 1)
endif
if cc.has_function('pthread_set_name_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency)
cdata.set('HAVE_PTHREAD_SET_NAME_NP', 1)
endif
if cc.compiles('int x = _Generic(0, default: 0);', name: '_Generic', args: test_args)
cdata.set('HAVE_C11_GENERIC', 1)
+22 -15
View File
@@ -132,6 +132,14 @@ static inline int pthread_cond_broadcast(pthread_cond_t *const cond) {
#else
#include <pthread.h>
#if defined(__FreeBSD__)
/* ALIGN from <sys/param.h> conflicts with ALIGN from "common/attributes.h" */
#define _SYS_PARAM_H_
#include <sys/types.h>
#endif
#ifdef HAVE_PTHREAD_NP_H
#include <pthread_np.h>
#endif
#define dav1d_init_thread() do {} while (0)
@@ -145,31 +153,30 @@ static inline void dav1d_set_thread_name(const char *const name) {
prctl(PR_SET_NAME, name);
}
#elif defined(__APPLE__)
#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(__APPLE__)
static inline void dav1d_set_thread_name(const char *const name) {
pthread_setname_np(name);
}
#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#if defined(__FreeBSD__)
/* ALIGN from <sys/param.h> conflicts with ALIGN from "common/attributes.h" */
#define _SYS_PARAM_H_
#include <sys/types.h>
#endif
#include <pthread_np.h>
static inline void dav1d_set_thread_name(const char *const name) {
pthread_set_name_np(pthread_self(), name);
}
#elif defined(__NetBSD__)
#elif defined(HAVE_PTHREAD_SETNAME_NP) && defined(__NetBSD__)
static inline void dav1d_set_thread_name(const char *const name) {
pthread_setname_np(pthread_self(), "%s", (void*)name);
}
#elif defined(HAVE_PTHREAD_SETNAME_NP)
static inline void dav1d_set_thread_name(const char *const name) {
pthread_setname_np(pthread_self(), name);
}
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
static inline void dav1d_set_thread_name(const char *const name) {
pthread_set_name_np(pthread_self(), name);
}
#elif defined(__HAIKU__)
#include <os/kernel/OS.h>