Split out the object fetch in virObject{Lock|Unlock} into a helper
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/util/virobject.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 792685b..5d5b6a3 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -309,6 +309,23 @@ 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 +341,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 +360,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.3