Skip to content

Commit

Permalink
rthreads: Add the ability to name threads
Browse files Browse the repository at this point in the history
  • Loading branch information
linkmauve committed Sep 1, 2020
1 parent 551f8ea commit 6e1affe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/rthreads/rthreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down
18 changes: 18 additions & 0 deletions rthreads/rthreads.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
*
Expand Down

0 comments on commit 6e1affe

Please sign in to comment.