mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
virThreadPool: Set thread worker name
Every thread created as a worker thread within a pool gets a name according to virThreadPoolJobFunc name. Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
55ebc93a08
commit
d20f5dde29
@ -2202,7 +2202,7 @@ virThreadPoolFree;
|
||||
virThreadPoolGetMaxWorkers;
|
||||
virThreadPoolGetMinWorkers;
|
||||
virThreadPoolGetPriorityWorkers;
|
||||
virThreadPoolNew;
|
||||
virThreadPoolNewFull;
|
||||
virThreadPoolSendJob;
|
||||
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user