提交 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,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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册