[PATCH v4 06/11] util: Use a mutex when retrieving threadpool data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/util/virthreadpool.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c
index e2e9fe4..7ceb090 100644
--- a/src/util/virthreadpool.c
+++ b/src/util/virthreadpool.c
@@ -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;
 }
 
 /*
-- 
2.4.11

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]