mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +00:00
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: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
8b03a609dd
commit
bf09f002b1
@ -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;
|
||||
virObjectRWLockablePtr obj = virObjectGetRWLockableObj(anyobj);
|
||||
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
virRWLockRead(&obj->lock);
|
||||
} else {
|
||||
virObjectPtr obj = anyobj;
|
||||
VIR_WARN("Object %p (%s) is not a virObjectRWLockable instance",
|
||||
anyobj, obj ? obj->klass->name : "(unknown)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -458,14 +472,12 @@ virObjectRWLockRead(void *anyobj)
|
||||
void
|
||||
virObjectRWLockWrite(void *anyobj)
|
||||
{
|
||||
if (virObjectIsClass(anyobj, virObjectRWLockableClass)) {
|
||||
virObjectRWLockablePtr obj = anyobj;
|
||||
virObjectRWLockablePtr obj = virObjectGetRWLockableObj(anyobj);
|
||||
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
virRWLockWrite(&obj->lock);
|
||||
} else {
|
||||
virObjectPtr obj = anyobj;
|
||||
VIR_WARN("Object %p (%s) is not a virObjectRWLockable instance",
|
||||
anyobj, obj ? obj->klass->name : "(unknown)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user