Skip to content

Commit 9af2581

Browse files
committed
rthreads: Add the ability to name threads
1 parent 3b37591 commit 9af2581

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

include/rthreads/rthreads.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ void sthread_join(sthread_t *thread);
101101
*/
102102
bool sthread_isself(sthread_t *thread);
103103

104+
/**
105+
* sthread_set_name:
106+
* @thread : pointer to thread object
107+
* @name : name to define for the thread (at most
108+
* 15 bytes)
109+
*
110+
* Set the thread name, useful for debugging.
111+
*/
112+
void sthread_setname(sthread_t *thread, const char *name);
113+
104114
/**
105115
* slock_new:
106116
*

rthreads/rthreads.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,24 @@ bool sthread_isself(sthread_t *thread)
318318
#endif
319319
}
320320

321+
/**
322+
* sthread_set_name:
323+
* @thread : pointer to thread object
324+
* @name : name to define for the thread (at most
325+
* 15 bytes)
326+
*
327+
* Set the thread name, useful for debugging.
328+
*/
329+
void sthread_setname(sthread_t *thread, const char *name)
330+
{
331+
if (!thread)
332+
return;
333+
// TODO: implement that for Windows and Apple too.
334+
#ifdef __linux__
335+
pthread_setname_np(thread->id, name);
336+
#endif
337+
}
338+
321339
/**
322340
* slock_new:
323341
*

0 commit comments

Comments
 (0)