Skip to content

Commit 3205631

Browse files
Added switch_thread_getname and switch_thread_setname functions
1 parent 82d06e5 commit 3205631

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

include/apr_thread_proc.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread,
277277
APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
278278
apr_status_t retval);
279279

280+
/**
281+
* Get name of thread
282+
* @param thread The thread that name required to get.
283+
* @param name The variable where is will be stored name of thread.
284+
*/
285+
APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name);
286+
280287
/**
281288
* block until the desired thread stops executing.
282289
* @param retval The return value from the dead thread.
@@ -285,6 +292,13 @@ APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
285292
APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
286293
apr_thread_t *thd);
287294

295+
/**
296+
* Set name of thread
297+
* @param thread The thread that name will be changed.
298+
* @param name The name of thread must be setted. If name is to long, then name stripped to max length supported by operation system.
299+
*/
300+
APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name);
301+
288302
/**
289303
* force the current thread to yield the processor
290304
*/

threadproc/beos/thread.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,13 @@ APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
240240
}
241241

242242
APR_POOL_IMPLEMENT_ACCESSOR(thread)
243+
244+
APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name)
245+
{
246+
return APR_ENOTIMPL;
247+
}
248+
249+
APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name)
250+
{
251+
return APR_ENOTIMPL;
252+
}

threadproc/netware/thread.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,12 @@ APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
256256

257257
APR_POOL_IMPLEMENT_ACCESSOR(thread)
258258

259+
APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name)
260+
{
261+
return APR_ENOTIMPL;
262+
}
259263

264+
APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name)
265+
{
266+
return APR_ENOTIMPL;
267+
}

threadproc/os2/thread.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ static void apr_thread_begin(void *arg)
7474
apr_pool_destroy(thread->pool);
7575
}
7676

77-
78-
7977
APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new, apr_threadattr_t *attr,
8078
apr_thread_start_t func, void *data,
8179
apr_pool_t *pool)
@@ -261,3 +259,13 @@ APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
261259

262260
return APR_SUCCESS;
263261
}
262+
263+
APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name)
264+
{
265+
return APR_ENOTIMPL;
266+
}
267+
268+
APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name)
269+
{
270+
return APR_ENOTIMPL;
271+
}

threadproc/unix/thread.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
#if APR_HAVE_PTHREAD_H
2424

25+
/* Unfortunately the kernel headers do not export the TASK_COMM_LEN
26+
macro. So we have to define it here. Used in apr_thread_getname and apr_thread_setname functions */
27+
#define TASK_COMM_LEN 16
28+
2529
/* Destroy the threadattr object */
2630
static apr_status_t threadattr_cleanup(void *data)
2731
{
@@ -193,6 +197,26 @@ APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new,
193197
}
194198
}
195199

200+
APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name)
201+
{
202+
size_t name_len;
203+
if (!name) {
204+
return APR_BADARG;
205+
}
206+
207+
name_len = strlen (name);
208+
if ( name_len >= TASK_COMM_LEN) {
209+
name = name + name_len - TASK_COMM_LEN + 1;
210+
}
211+
return pthread_setname_np(*thread->td, name);
212+
}
213+
214+
APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name)
215+
{
216+
*name = apr_pcalloc(thread->pool, TASK_COMM_LEN);
217+
return pthread_getname_np(*thread->td, *name, TASK_COMM_LEN);
218+
}
219+
196220
APR_DECLARE(apr_os_thread_t) apr_os_thread_current(void)
197221
{
198222
return pthread_self();

threadproc/win32/thread.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,13 @@ APR_DECLARE(int) apr_os_thread_equal(apr_os_thread_t tid1,
284284
}
285285

286286
APR_POOL_IMPLEMENT_ACCESSOR(thread)
287+
288+
APR_DECLARE(apr_status_t) apr_thread_setname(apr_thread_t *thread, const char *name)
289+
{
290+
return APR_ENOTIMPL;
291+
}
292+
293+
APR_DECLARE(apr_status_t) apr_thread_getname(apr_thread_t *thread, char ** name)
294+
{
295+
return APR_ENOTIMPL;
296+
}

0 commit comments

Comments
 (0)