]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Use a mutex when retrieving threadpool data
authorErik Skultety <eskultet@redhat.com>
Mon, 4 Apr 2016 20:32:16 +0000 (22:32 +0200)
committerErik Skultety <eskultet@redhat.com>
Mon, 18 Apr 2016 15:07:09 +0000 (17:07 +0200)
So far, the values the affected getters retrieve are static, i.e. there's no
way of changing them during runtime. But admin interface will later enable
not only getting but changing them as well. So to prevent phenomenons like
torn reads or concurrent reads and writes of unaligned values, use mutual
exclusion when getting these values (writes do, understandably, use them
already).

Signed-off-by: Erik Skultety <eskultet@redhat.com>
src/util/virthreadpool.c

index e2e9fe4699388e9de201cf95f9f8349537c836c7..7ceb090a998b80fc5b76576e1ed8edf6c504563b 100644 (file)
@@ -286,17 +286,35 @@ void virThreadPoolFree(virThreadPoolPtr pool)
 
 size_t virThreadPoolGetMinWorkers(virThreadPoolPtr pool)
 {
-    return pool->minWorkers;
+    size_t ret;
+
+    virMutexLock(&pool->mutex);
+    ret = pool->minWorkers;
+    virMutexUnlock(&pool->mutex);
+
+    return ret;
 }
 
 size_t virThreadPoolGetMaxWorkers(virThreadPoolPtr pool)
 {
-    return pool->maxWorkers;
+    size_t ret;
+
+    virMutexLock(&pool->mutex);
+    ret = pool->maxWorkers;
+    virMutexUnlock(&pool->mutex);
+
+    return ret;
 }
 
 size_t virThreadPoolGetPriorityWorkers(virThreadPoolPtr pool)
 {
-    return pool->nPrioWorkers;
+    size_t ret;
+
+    virMutexLock(&pool->mutex);
+    ret = pool->nPrioWorkers;
+    virMutexUnlock(&pool->mutex);
+
+    return ret;
 }
 
 /*