util: always initialize priority condition

Even if we have no priority threads on pool creation we can add them thru
virThreadPoolSetParameters later.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Nikolay Shirokovskiy 2020-07-10 14:36:54 +03:00
parent c5bf40bfa6
commit 018e213f5d

View File

@ -245,6 +245,8 @@ virThreadPoolNewFull(size_t minWorkers,
goto error; goto error;
if (virCondInit(&pool->cond) < 0) if (virCondInit(&pool->cond) < 0)
goto error; goto error;
if (virCondInit(&pool->prioCond) < 0)
goto error;
if (virCondInit(&pool->quit_cond) < 0) if (virCondInit(&pool->quit_cond) < 0)
goto error; goto error;
@ -255,13 +257,8 @@ virThreadPoolNewFull(size_t minWorkers,
if (virThreadPoolExpand(pool, minWorkers, false) < 0) if (virThreadPoolExpand(pool, minWorkers, false) < 0)
goto error; goto error;
if (prioWorkers) { if (virThreadPoolExpand(pool, prioWorkers, true) < 0)
if (virCondInit(&pool->prioCond) < 0) goto error;
goto error;
if (virThreadPoolExpand(pool, prioWorkers, true) < 0)
goto error;
}
return pool; return pool;
@ -274,7 +271,6 @@ virThreadPoolNewFull(size_t minWorkers,
void virThreadPoolFree(virThreadPoolPtr pool) void virThreadPoolFree(virThreadPoolPtr pool)
{ {
virThreadPoolJobPtr job; virThreadPoolJobPtr job;
bool priority = false;
if (!pool) if (!pool)
return; return;
@ -283,10 +279,8 @@ void virThreadPoolFree(virThreadPoolPtr pool)
pool->quit = true; pool->quit = true;
if (pool->nWorkers > 0) if (pool->nWorkers > 0)
virCondBroadcast(&pool->cond); virCondBroadcast(&pool->cond);
if (pool->nPrioWorkers > 0) { if (pool->nPrioWorkers > 0)
priority = true;
virCondBroadcast(&pool->prioCond); virCondBroadcast(&pool->prioCond);
}
while (pool->nWorkers > 0 || pool->nPrioWorkers > 0) while (pool->nWorkers > 0 || pool->nPrioWorkers > 0)
ignore_value(virCondWait(&pool->quit_cond, &pool->mutex)); ignore_value(virCondWait(&pool->quit_cond, &pool->mutex));
@ -301,10 +295,8 @@ void virThreadPoolFree(virThreadPoolPtr pool)
virMutexDestroy(&pool->mutex); virMutexDestroy(&pool->mutex);
virCondDestroy(&pool->quit_cond); virCondDestroy(&pool->quit_cond);
virCondDestroy(&pool->cond); virCondDestroy(&pool->cond);
if (priority) { VIR_FREE(pool->prioWorkers);
VIR_FREE(pool->prioWorkers); virCondDestroy(&pool->prioCond);
virCondDestroy(&pool->prioCond);
}
VIR_FREE(pool); VIR_FREE(pool);
} }