From 6e1affe1cff8a7ce502c9f5da9e6b1d4175fb9f4 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 31 Aug 2020 23:33:15 +0200 Subject: [PATCH] rthreads: Add the ability to name threads --- include/rthreads/rthreads.h | 10 ++++++++++ rthreads/rthreads.c | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/rthreads/rthreads.h b/include/rthreads/rthreads.h index 5887c4c3..3b1ec7c8 100644 --- a/include/rthreads/rthreads.h +++ b/include/rthreads/rthreads.h @@ -101,6 +101,16 @@ void sthread_join(sthread_t *thread); */ bool sthread_isself(sthread_t *thread); +/** + * sthread_set_name: + * @thread : pointer to thread object + * @name : name to define for the thread (at most + * 15 bytes) + * + * Set the thread name, useful for debugging. + */ +void sthread_setname(sthread_t *thread, const char *name); + /** * slock_new: * diff --git a/rthreads/rthreads.c b/rthreads/rthreads.c index 3c4099b1..5d39fa06 100644 --- a/rthreads/rthreads.c +++ b/rthreads/rthreads.c @@ -318,6 +318,24 @@ bool sthread_isself(sthread_t *thread) #endif } +/** + * sthread_set_name: + * @thread : pointer to thread object + * @name : name to define for the thread (at most + * 15 bytes) + * + * Set the thread name, useful for debugging. + */ +void sthread_setname(sthread_t *thread, const char *name) +{ + if (!thread) + return; + // TODO: implement that for Windows and Apple too. +#ifdef __linux__ + pthread_setname_np(thread->id, name); +#endif +} + /** * slock_new: *