[libvirt] [PATCH v4 07/11] util: Add more getters to threadpool parameters

Erik Skultety eskultet at redhat.com
Fri Apr 8 11:50:07 UTC 2016


In order for the client to see all thread counts and limits, current total
and free worker count getters need to be introduced. Client might also be
interested in the job queue length, so provide a getter for that too. As with
the other getters, preparing for the admin interface, mutual exclusion is used
within all getters.

Signed-off-by: Erik Skultety <eskultet at redhat.com>
---
 src/libvirt_private.syms |  3 +++
 src/util/virthreadpool.c | 33 +++++++++++++++++++++++++++++++++
 src/util/virthreadpool.h |  3 +++
 3 files changed, 39 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 068bc00..021bb5b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2352,6 +2352,9 @@ virThreadJobSetWorker;
 
 # util/virthreadpool.h
 virThreadPoolFree;
+virThreadPoolGetCurrentWorkers;
+virThreadPoolGetFreeWorkers;
+virThreadPoolGetJobQueueDepth;
 virThreadPoolGetMaxWorkers;
 virThreadPoolGetMinWorkers;
 virThreadPoolGetPriorityWorkers;
diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c
index 7ceb090..fec8620 100644
--- a/src/util/virthreadpool.c
+++ b/src/util/virthreadpool.c
@@ -317,6 +317,39 @@ size_t virThreadPoolGetPriorityWorkers(virThreadPoolPtr pool)
     return ret;
 }
 
+size_t virThreadPoolGetCurrentWorkers(virThreadPoolPtr pool)
+{
+    size_t ret;
+
+    virMutexLock(&pool->mutex);
+    ret = pool->nWorkers;
+    virMutexUnlock(&pool->mutex);
+
+    return ret;
+}
+
+size_t virThreadPoolGetFreeWorkers(virThreadPoolPtr pool)
+{
+    size_t ret;
+
+    virMutexLock(&pool->mutex);
+    ret = pool->freeWorkers;
+    virMutexUnlock(&pool->mutex);
+
+    return ret;
+}
+
+size_t virThreadPoolGetJobQueueDepth(virThreadPoolPtr pool)
+{
+    size_t ret;
+
+    virMutexLock(&pool->mutex);
+    ret = pool->jobQueueDepth;
+    virMutexUnlock(&pool->mutex);
+
+    return ret;
+}
+
 /*
  * @priority - job priority
  * Return: 0 on success, -1 otherwise
diff --git a/src/util/virthreadpool.h b/src/util/virthreadpool.h
index 538b62f..bc0c907 100644
--- a/src/util/virthreadpool.h
+++ b/src/util/virthreadpool.h
@@ -46,6 +46,9 @@ virThreadPoolPtr virThreadPoolNewFull(size_t minWorkers,
 size_t virThreadPoolGetMinWorkers(virThreadPoolPtr pool);
 size_t virThreadPoolGetMaxWorkers(virThreadPoolPtr pool);
 size_t virThreadPoolGetPriorityWorkers(virThreadPoolPtr pool);
+size_t virThreadPoolGetCurrentWorkers(virThreadPoolPtr pool);
+size_t virThreadPoolGetFreeWorkers(virThreadPoolPtr pool);
+size_t virThreadPoolGetJobQueueDepth(virThreadPoolPtr pool);
 
 void virThreadPoolFree(virThreadPoolPtr pool);
 
-- 
2.4.11




More information about the libvir-list mailing list