Every thread created as a worker thread within a pool gets a name according to virThreadPoolJobFunc name.
Signed-off-by: Jiri Denemark <jdene...@redhat.com> --- src/libvirt_private.syms | 2 +- src/util/virthreadpool.c | 44 +++++++++++++++++++++++++++----------------- src/util/virthreadpool.h | 14 +++++++++----- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4980305..90bf08b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2195,7 +2195,7 @@ virThreadPoolFree; virThreadPoolGetMaxWorkers; virThreadPoolGetMinWorkers; virThreadPoolGetPriorityWorkers; -virThreadPoolNew; +virThreadPoolNewFull; virThreadPoolSendJob; diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index 98d2124..ed22486 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -58,6 +58,7 @@ struct _virThreadPool { bool quit; virThreadPoolJobFunc jobFunc; + const char *jobFuncName; void *jobOpaque; virThreadPoolJobList jobList; size_t jobQueueDepth; @@ -156,11 +157,13 @@ static void virThreadPoolWorker(void *opaque) virMutexUnlock(&pool->mutex); } -virThreadPoolPtr virThreadPoolNew(size_t minWorkers, - size_t maxWorkers, - size_t prioWorkers, - virThreadPoolJobFunc func, - void *opaque) +virThreadPoolPtr +virThreadPoolNewFull(size_t minWorkers, + size_t maxWorkers, + size_t prioWorkers, + virThreadPoolJobFunc func, + const char *funcName, + void *opaque) { virThreadPoolPtr pool; size_t i; @@ -175,6 +178,7 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers, pool->jobList.tail = pool->jobList.head = NULL; pool->jobFunc = func; + pool->jobFuncName = funcName; pool->jobOpaque = opaque; if (virMutexInit(&pool->mutex) < 0) @@ -196,10 +200,12 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers, data->pool = pool; data->cond = &pool->cond; - if (virThreadCreate(&pool->workers[i], - true, - virThreadPoolWorker, - data) < 0) { + if (virThreadCreateFull(&pool->workers[i], + true, + virThreadPoolWorker, + pool->jobFuncName, + true, + data) < 0) { goto error; } pool->nWorkers++; @@ -218,10 +224,12 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers, data->cond = &pool->prioCond; data->priority = true; - if (virThreadCreate(&pool->prioWorkers[i], - true, - virThreadPoolWorker, - data) < 0) { + if (virThreadCreateFull(&pool->prioWorkers[i], + true, + virThreadPoolWorker, + pool->jobFuncName, + true, + data) < 0) { goto error; } pool->nPrioWorkers++; @@ -329,10 +337,12 @@ int virThreadPoolSendJob(virThreadPoolPtr pool, data->pool = pool; data->cond = &pool->cond; - if (virThreadCreate(&pool->workers[pool->nWorkers - 1], - true, - virThreadPoolWorker, - data) < 0) { + if (virThreadCreateFull(&pool->workers[pool->nWorkers - 1], + true, + virThreadPoolWorker, + pool->jobFuncName, + true, + data) < 0) { VIR_FREE(data); pool->nWorkers--; goto error; diff --git a/src/util/virthreadpool.h b/src/util/virthreadpool.h index cbac600..538b62f 100644 --- a/src/util/virthreadpool.h +++ b/src/util/virthreadpool.h @@ -33,11 +33,15 @@ typedef virThreadPool *virThreadPoolPtr; typedef void (*virThreadPoolJobFunc)(void *jobdata, void *opaque); -virThreadPoolPtr virThreadPoolNew(size_t minWorkers, - size_t maxWorkers, - size_t prioWorkers, - virThreadPoolJobFunc func, - void *opaque) ATTRIBUTE_NONNULL(4); +# define virThreadPoolNew(min, max, prio, func, opaque) \ + virThreadPoolNewFull(min, max, prio, func, #func, opaque) + +virThreadPoolPtr virThreadPoolNewFull(size_t minWorkers, + size_t maxWorkers, + size_t prioWorkers, + virThreadPoolJobFunc func, + const char *funcName, + void *opaque) ATTRIBUTE_NONNULL(4); size_t virThreadPoolGetMinWorkers(virThreadPoolPtr pool); size_t virThreadPoolGetMaxWorkers(virThreadPoolPtr pool); -- 2.3.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list