mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 19:41:16 +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;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user