From 0bb33164d0b145ee7a8b4159fa44babe6a01f842 Mon Sep 17 00:00:00 2001 From: Wei Gong Date: Mon, 18 Mar 2024 21:31:14 +0800 Subject: [PATCH] virthreadpool: create threads from the newly expanded workers when the thread pool is dynamically expanded, threads should not be created from the existing workers; they should be created from the newly expanded workers Signed-off-by: Wei Gong Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- src/util/virthreadpool.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index d45fa92061..e00accd9eb 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -184,7 +184,7 @@ virThreadPoolExpand(virThreadPool *pool, size_t gain, bool priority) size_t i = 0; struct virThreadPoolWorkerData *data = NULL; - VIR_EXPAND_N(*workers, *curWorkers, gain); + VIR_REALLOC_N(*workers, *curWorkers + gain); for (i = 0; i < gain; i++) { g_autofree char *name = NULL; @@ -199,7 +199,7 @@ virThreadPoolExpand(virThreadPool *pool, size_t gain, bool priority) else name = g_strdup(pool->jobName); - if (virThreadCreateFull(&(*workers)[i], + if (virThreadCreateFull(&(*workers)[*curWorkers], false, virThreadPoolWorker, name, @@ -207,15 +207,13 @@ virThreadPoolExpand(virThreadPool *pool, size_t gain, bool priority) data) < 0) { VIR_FREE(data); virReportSystemError(errno, "%s", _("Failed to create thread")); - goto error; + return -1; } + + (*curWorkers)++; } return 0; - - error: - *curWorkers -= gain - i; - return -1; } virThreadPool *