summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-11-26 14:31:14 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-11-27 21:03:36 -0500
commitf05d65e5cf4b376a6bf1eeed17356f8e7767b389 (patch)
tree120367d126dfc7601dcb97abc699ffa4463be641 /src
parentaecdabb625841052a68fd3b5510c56b138693c9a (diff)
downloadbfs-f05d65e5cf4b376a6bf1eeed17356f8e7767b389.tar.xz
thread: New thread_setname() function
Diffstat (limited to 'src')
-rw-r--r--src/thread.c12
-rw-r--r--src/thread.h5
2 files changed, 17 insertions, 0 deletions
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 <errno.h>
#include <pthread.h>
+#if __has_include(<pthread_np.h>)
+# include <pthread_np.h>
+#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));
}
diff --git a/src/thread.h b/src/thread.h
index 7d12468..3dd8422 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -22,6 +22,11 @@ typedef void *thread_fn(void *arg);
int thread_create(pthread_t *thread, const pthread_attr_t *attr, thread_fn *fn, void *arg);
/**
+ * Set the name of a thread.
+ */
+void thread_setname(pthread_t thread, const char *name);
+
+/**
* Wrapper for pthread_join().
*/
void thread_join(pthread_t thread, void **ret);