]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virthreadpool: create threads from the newly expanded workers
authorWei Gong <gongwei833x@gmail.com>
Mon, 18 Mar 2024 13:31:14 +0000 (21:31 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 18 Mar 2024 14:12:46 +0000 (15:12 +0100)
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 <gongwei833x@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virthreadpool.c

index d45fa920613d16084d0cd65323a74e2a44794210..e00accd9eb1413f059930f819de0678d8e5422b9 100644 (file)
@@ -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 *