diff --git a/lib/isc/include/isc/task.h b/lib/isc/include/isc/task.h index 505617c678..c6dbe944a1 100644 --- a/lib/isc/include/isc/task.h +++ b/lib/isc/include/isc/task.h @@ -453,6 +453,21 @@ isc_task_destroy(isc_task_t **taskp); * All resources used by the task will be freed. */ +void +isc_task_setname(isc_task_t *task, char *name, void *tag); +/* + * Name 'task'. + * + * Notes: + * + * Only the first 15 characters of 'name' will be copied. + * + * Naming a task is currently only useful for debugging purposes. + * + * Requires: + * + * 'task' is a valid task. + */ /***** ***** Task Manager. diff --git a/lib/isc/task.c b/lib/isc/task.c index 269ff2f7db..07367a8bb5 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -26,6 +26,8 @@ #include +#include + #include #include #include @@ -36,6 +38,8 @@ #include #include +#define ISC_TASK_NAMES 1 + #ifdef ISC_TASK_TRACE #define XTRACE(m) printf("task %p thread %lu: %s\n", \ task, isc_thread_self(), (m)) @@ -75,6 +79,10 @@ struct isc_task { isc_eventlist_t on_shutdown; unsigned int quantum; unsigned int flags; +#ifdef ISC_TASK_NAMES + char name[16]; + void * tag; +#endif /* Locked by task manager lock. */ LINK(isc_task_t) link; LINK(isc_task_t) ready_link; @@ -170,6 +178,10 @@ isc_task_create(isc_taskmgr_t *manager, isc_mem_t *mctx, unsigned int quantum, INIT_LIST(task->on_shutdown); task->quantum = quantum; task->flags = 0; +#ifdef ISC_TASK_NAMES + task->name[0] = '\0'; + task->tag = NULL; +#endif INIT_LINK(task, link); INIT_LINK(task, ready_link); @@ -664,7 +676,27 @@ isc_task_destroy(isc_task_t **taskp) { isc_task_detach(taskp); } +void +isc_task_setname(isc_task_t *task, char *name, void *tag) { + /* + * Name 'task'. + */ + + REQUIRE(VALID_TASK(task)); + +#ifdef ISC_TASK_NAMES + LOCK(&task->lock); + memset(task->name, 0, sizeof(task->name)); + strncpy(task->name, name, sizeof(task->name) - 1); + task->tag = tag; + UNLOCK(&task->lock); +#else + (void)name; + (void)tag; +#endif + +} /*** *** Task Manager.