[PATCH 2/6] virObject: Introduce virObjectRecursiveLockableNew

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

 



Sometimes we need the lock in virObjectLockable to be recursive.
Because of the nature of pthreads we don't need a special class
for that - the pthread_* APIs don't distinguish between normal
and recursive locks.

Based-on-work-of: John Ferlan <jferlan@xxxxxxxxxx>
Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virobject.c     | 22 +++++++++++++++++++---
 src/util/virobject.h     |  4 ++++
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3b14d7d15..fcf378105 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2417,6 +2417,7 @@ virObjectListFreeCount;
 virObjectLock;
 virObjectLockableNew;
 virObjectNew;
+virObjectRecursiveLockableNew;
 virObjectRef;
 virObjectRWLockableNew;
 virObjectRWLockRead;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index b2fc63aec..1d82e826b 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -257,8 +257,9 @@ virObjectNew(virClassPtr klass)
 }
 
 
-void *
-virObjectLockableNew(virClassPtr klass)
+static void *
+virObjectLockableNewInternal(virClassPtr klass,
+                             bool recursive)
 {
     virObjectLockablePtr obj;
 
@@ -272,7 +273,8 @@ virObjectLockableNew(virClassPtr klass)
     if (!(obj = virObjectNew(klass)))
         return NULL;
 
-    if (virMutexInit(&obj->lock) < 0) {
+    if ((!recursive && virMutexInit(&obj->lock) < 0) ||
+        (recursive && virMutexInitRecursive(&obj->lock) < 0)) {
         virReportSystemError(errno, "%s",
                              _("Unable to initialize mutex"));
         virObjectUnref(obj);
@@ -283,6 +285,20 @@ virObjectLockableNew(virClassPtr klass)
 }
 
 
+void *
+virObjectLockableNew(virClassPtr klass)
+{
+    return virObjectLockableNewInternal(klass, false);
+}
+
+
+void *
+virObjectRecursiveLockableNew(virClassPtr klass)
+{
+    return virObjectLockableNewInternal(klass, true);
+}
+
+
 void *
 virObjectRWLockableNew(virClassPtr klass)
 {
diff --git a/src/util/virobject.h b/src/util/virobject.h
index ac6cf22f9..367d505ae 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -116,6 +116,10 @@ void *
 virObjectLockableNew(virClassPtr klass)
     ATTRIBUTE_NONNULL(1);
 
+void *
+virObjectRecursiveLockableNew(virClassPtr klass)
+    ATTRIBUTE_NONNULL(1);
+
 void *
 virObjectRWLockableNew(virClassPtr klass)
     ATTRIBUTE_NONNULL(1);
-- 
2.13.6

--
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]

  Powered by Linux