From f05d65e5cf4b376a6bf1eeed17356f8e7767b389 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 26 Nov 2024 14:31:14 -0500 Subject: thread: New thread_setname() function --- src/thread.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/thread.c') diff --git a/src/thread.c b/src/thread.c index d61ff8c..b3604f8 100644 --- a/src/thread.c +++ b/src/thread.c @@ -9,6 +9,10 @@ #include #include +#if __has_include() +# include +#endif + #define THREAD_FALLIBLE(expr) \ do { \ int err = expr; \ @@ -32,6 +36,14 @@ int thread_create(pthread_t *thread, const pthread_attr_t *attr, thread_fn *fn, THREAD_FALLIBLE(pthread_create(thread, attr, fn, arg)); } +void thread_setname(pthread_t thread, const char *name) { +#if BFS_HAS_PTHREAD_SETNAME_NP + pthread_setname_np(thread, name); +#elif BFS_HAS_PTHREAD_SET_NAME_NP + pthread_set_name_np(thread, name); +#endif +} + void thread_join(pthread_t thread, void **ret) { THREAD_INFALLIBLE(pthread_join(thread, ret)); } -- cgit v1.2.3