提交 bf09f002 编写于 作者: J John Ferlan

util: Introduce virObjectGetRWLockableObj

Introduce a helper to handle the error path more cleanly. The same
as virObjectGetLockableObj in order to essentially follow the original
logic of commit 'b545f65d' to ensure that the input argument at least
has some validity before using.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 8b03a609
......@@ -383,6 +383,22 @@ virObjectGetLockableObj(void *anyobj)
}
static virObjectRWLockablePtr
virObjectGetRWLockableObj(void *anyobj)
{
virObjectPtr obj;
if (virObjectIsClass(anyobj, virObjectRWLockableClass))
return anyobj;
obj = anyobj;
VIR_WARN("Object %p (%s) is not a virObjectRWLockable instance",
anyobj, obj ? obj->klass->name : "(unknown)");
return NULL;
}
/**
* virObjectLock:
* @anyobj: any instance of virObjectLockable or virObjectRWLockable
......@@ -427,14 +443,12 @@ virObjectLock(void *anyobj)
void
virObjectRWLockRead(void *anyobj)
{
if (virObjectIsClass(anyobj, virObjectRWLockableClass)) {
virObjectRWLockablePtr obj = anyobj;
virRWLockRead(&obj->lock);
} else {
virObjectPtr obj = anyobj;
VIR_WARN("Object %p (%s) is not a virObjectRWLockable instance",
anyobj, obj ? obj->klass->name : "(unknown)");
}
virObjectRWLockablePtr obj = virObjectGetRWLockableObj(anyobj);
if (!obj)
return;
virRWLockRead(&obj->lock);
}
......@@ -458,14 +472,12 @@ virObjectRWLockRead(void *anyobj)
void
virObjectRWLockWrite(void *anyobj)
{
if (virObjectIsClass(anyobj, virObjectRWLockableClass)) {
virObjectRWLockablePtr obj = anyobj;
virRWLockWrite(&obj->lock);
} else {
virObjectPtr obj = anyobj;
VIR_WARN("Object %p (%s) is not a virObjectRWLockable instance",
anyobj, obj ? obj->klass->name : "(unknown)");
}
virObjectRWLockablePtr obj = virObjectGetRWLockableObj(anyobj);
if (!obj)
return;
virRWLockWrite(&obj->lock);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册