提交 d20f5dde 编写于 作者: J Jiri Denemark

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: NJiri Denemark <jdenemar@redhat.com>
上级 55ebc93a
......@@ -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,10 +157,12 @@ static void virThreadPoolWorker(void *opaque)
virMutexUnlock(&pool->mutex);
}
virThreadPoolPtr virThreadPoolNew(size_t minWorkers,
virThreadPoolPtr
virThreadPoolNewFull(size_t minWorkers,
size_t maxWorkers,
size_t prioWorkers,
virThreadPoolJobFunc func,
const char *funcName,
void *opaque)
{
virThreadPoolPtr pool;
......@@ -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,9 +200,11 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers,
data->pool = pool;
data->cond = &pool->cond;
if (virThreadCreate(&pool->workers[i],
if (virThreadCreateFull(&pool->workers[i],
true,
virThreadPoolWorker,
pool->jobFuncName,
true,
data) < 0) {
goto error;
}
......@@ -218,9 +224,11 @@ virThreadPoolPtr virThreadPoolNew(size_t minWorkers,
data->cond = &pool->prioCond;
data->priority = true;
if (virThreadCreate(&pool->prioWorkers[i],
if (virThreadCreateFull(&pool->prioWorkers[i],
true,
virThreadPoolWorker,
pool->jobFuncName,
true,
data) < 0) {
goto error;
}
......@@ -329,9 +337,11 @@ int virThreadPoolSendJob(virThreadPoolPtr pool,
data->pool = pool;
data->cond = &pool->cond;
if (virThreadCreate(&pool->workers[pool->nWorkers - 1],
if (virThreadCreateFull(&pool->workers[pool->nWorkers - 1],
true,
virThreadPoolWorker,
pool->jobFuncName,
true,
data) < 0) {
VIR_FREE(data);
pool->nWorkers--;
......
......@@ -33,10 +33,14 @@ typedef virThreadPool *virThreadPoolPtr;
typedef void (*virThreadPoolJobFunc)(void *jobdata, void *opaque);
virThreadPoolPtr virThreadPoolNew(size_t minWorkers,
# 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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册