Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a helper function to set thread name in rthread #169

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions include/rthreads/rthreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ int sthread_detach(sthread_t *thread);
* @thread to terminate. If that thread has already terminated, then
* it will return immediately. The thread specified by @thread must
* be joinable.
*
* Returns: 0 on success, otherwise it returns a non-zero error number.
*/
void sthread_join(sthread_t *thread);

Expand All @@ -103,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
20 changes: 18 additions & 2 deletions rthreads/rthreads.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@ int sthread_detach(sthread_t *thread)
* @thread to terminate. If that thread has already terminated, then
* it will return immediately. The thread specified by @thread must
* be joinable.
*
* Returns: 0 on success, otherwise it returns a non-zero error number.
*/
void sthread_join(sthread_t *thread)
{
Expand Down Expand Up @@ -320,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