Skip to content

Commit

Permalink
Added switch_thread_getname and switch_thread_setname functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-safarov committed Jan 15, 2017
1 parent 82d06e5 commit 3205631
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 2 deletions.
14 changes: 14 additions & 0 deletions include/apr_thread_proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread,
APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
apr_status_t retval);

/**
* Get name of thread
* @param thread The thread that name required to get.
* @param name The variable where is will be stored name of thread.
*/
APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name);

/**
* block until the desired thread stops executing.
* @param retval The return value from the dead thread.
Expand All @@ -285,6 +292,13 @@ APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
apr_thread_t *thd);

/**
* Set name of thread
* @param thread The thread that name will be changed.
* @param name The name of thread must be setted. If name is to long, then name stripped to max length supported by operation system.
*/
APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name);

/**
* force the current thread to yield the processor
*/
Expand Down
10 changes: 10 additions & 0 deletions threadproc/beos/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,13 @@ APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
}

APR_POOL_IMPLEMENT_ACCESSOR(thread)

APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name)
{
return APR_ENOTIMPL;
}

APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name)
{
return APR_ENOTIMPL;
}
8 changes: 8 additions & 0 deletions threadproc/netware/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,12 @@ APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,

APR_POOL_IMPLEMENT_ACCESSOR(thread)

APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name)
{
return APR_ENOTIMPL;
}

APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name)
{
return APR_ENOTIMPL;
}
12 changes: 10 additions & 2 deletions threadproc/os2/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ static void apr_thread_begin(void *arg)
apr_pool_destroy(thread->pool);
}



APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t *attr,
apr_thread_start_t func, void *data,
apr_pool_t *pool)
Expand Down Expand Up @@ -261,3 +259,13 @@ APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,

return APR_SUCCESS;
}

APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name)
{
return APR_ENOTIMPL;
}

APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name)
{
return APR_ENOTIMPL;
}
24 changes: 24 additions & 0 deletions threadproc/unix/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#if APR_HAVE_PTHREAD_H

/* Unfortunately the kernel headers do not export the TASK_COMM_LEN
macro. So we have to define it here. Used in apr_thread_getname and apr_thread_setname functions */
#define TASK_COMM_LEN 16

/* Destroy the threadattr object */
static apr_status_t threadattr_cleanup(void *data)
{
Expand Down Expand Up @@ -193,6 +197,26 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
}
}

APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name)
{
size_t name_len;
if (!name) {
return APR_BADARG;
}

name_len = strlen (name);
if ( name_len >= TASK_COMM_LEN) {
name = name + name_len - TASK_COMM_LEN + 1;
}
return pthread_setname_np(*thread->td, name);
}

APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name)
{
*name = apr_pcalloc(thread->pool, TASK_COMM_LEN);
return pthread_getname_np(*thread->td, *name, TASK_COMM_LEN);
}

APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void)
{
return pthread_self();
Expand Down
10 changes: 10 additions & 0 deletions threadproc/win32/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,13 @@ APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1,
}

APR_POOL_IMPLEMENT_ACCESSOR(thread)

APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name)
{
return APR_ENOTIMPL;
}

APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name)
{
return APR_ENOTIMPL;
}

0 comments on commit 3205631

Please sign in to comment.