[PATCH 2/9] util: Introduce virObjectGetLockableObj

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

 



Split out the object fetch in virObject{Lock|Unlock} into a helper

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/util/virobject.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/util/virobject.c b/src/util/virobject.c
index 792685b..34805d3 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -309,6 +309,22 @@ virObjectRef(void *anyobj)
 }
 
 
+static virObjectLockablePtr
+virObjectGetLockableObj(void *anyobj)
+{
+    virObjectPtr obj;
+
+    if (virObjectIsClass(anyobj, virObjectLockableClass))
+        return anyobj;
+
+    obj = anyobj;
+    VIR_WARN("Object %p (%s) is not a virObjectLockable instance",
+              anyobj, obj ? obj->klass->name : "(unknown)");
+
+    return NULL;
+}
+
+
 /**
  * virObjectLock:
  * @anyobj: any instance of virObjectLockablePtr
@@ -324,13 +340,10 @@ virObjectRef(void *anyobj)
 void
 virObjectLock(void *anyobj)
 {
-    virObjectLockablePtr obj = anyobj;
+    virObjectLockablePtr obj = virObjectGetLockableObj(anyobj);
 
-    if (!virObjectIsClass(obj, virObjectLockableClass)) {
-        VIR_WARN("Object %p (%s) is not a virObjectLockable instance",
-                 obj, obj ? obj->parent.klass->name : "(unknown)");
+    if (!obj)
         return;
-    }
 
     virMutexLock(&obj->lock);
 }
@@ -346,13 +359,10 @@ virObjectLock(void *anyobj)
 void
 virObjectUnlock(void *anyobj)
 {
-    virObjectLockablePtr obj = anyobj;
+    virObjectLockablePtr obj = virObjectGetLockableObj(anyobj);
 
-    if (!virObjectIsClass(obj, virObjectLockableClass)) {
-        VIR_WARN("Object %p (%s) is not a virObjectLockable instance",
-                 obj, obj ? obj->parent.klass->name : "(unknown)");
+    if (!obj)
         return;
-    }
 
     virMutexUnlock(&obj->lock);
 }
-- 
2.9.4

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