Let's use the ObjectRWLockable for the various list lock mgmt.
Only time need Write lock will be for Add/Remove logic.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/virsecretobj.c | 36 ++++++++++++++++++------------------
1 file changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 4dca152d48..47e0b28968 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -52,7 +52,7 @@ static void virSecretObjDispose(void *obj);
static void virSecretObjListDispose(void *obj);
struct _virSecretObjList {
- virObjectLockable parent;
+ virObjectRWLockable parent;
/* uuid string -> virSecretObj mapping
* for O(1), lockless lookup-by-uuid */
@@ -74,7 +74,7 @@ virSecretObjOnceInit(void)
virSecretObjDispose)))
return -1;
- if (!(virSecretObjListClass = virClassNew(virClassForObjectLockable(),
+ if (!(virSecretObjListClass = virClassNew(virClassForObjectRWLockable(),
"virSecretObjList",
sizeof(virSecretObjList),
virSecretObjListDispose)))
@@ -123,7 +123,7 @@ virSecretObjListNew(void)
if (virSecretObjInitialize() < 0)
return NULL;
- if (!(secrets = virObjectLockableNew(virSecretObjListClass)))
+ if (!(secrets = virObjectRWLockableNew(virSecretObjListClass)))
return NULL;
if (!(secrets->objs = virHashCreate(50, virObjectFreeHashData))) {
@@ -193,9 +193,9 @@ virSecretObjListFindByUUID(virSecretObjListPtr secrets,
{
virSecretObjPtr obj;
- virObjectLock(secrets);
+ virObjectRWLockRead(secrets);
obj = virSecretObjListFindByUUIDLocked(secrets, uuidstr);
- virObjectUnlock(secrets);
+ virObjectRWUnlock(secrets);
if (obj)
virObjectLock(obj);
return obj;
@@ -272,9 +272,9 @@ virSecretObjListFindByUsage(virSecretObjListPtr secrets,
{
virSecretObjPtr obj;
- virObjectLock(secrets);
+ virObjectRWLockRead(secrets);
obj = virSecretObjListFindByUsageLocked(secrets, usageType, usageID);
- virObjectUnlock(secrets);
+ virObjectRWUnlock(secrets);
if (obj)
virObjectLock(obj);
return obj;
@@ -305,12 +305,12 @@ virSecretObjListRemove(virSecretObjListPtr secrets,
virObjectRef(obj);
virObjectUnlock(obj);
- virObjectLock(secrets);
+ virObjectRWLockWrite(secrets);
virObjectLock(obj);
virHashRemoveEntry(secrets->objs, uuidstr);
virObjectUnlock(obj);
virObjectUnref(obj);
- virObjectUnlock(secrets);
+ virObjectRWUnlock(secrets);
}
@@ -336,7 +336,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
virSecretObjPtr ret = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
- virObjectLock(secrets);
+ virObjectRWLockWrite(secrets);
if (oldDef)
*oldDef = NULL;
@@ -405,7 +405,7 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
cleanup:
virSecretObjEndAPI(&obj);
- virObjectUnlock(secrets);
+ virObjectRWUnlock(secrets);
return ret;
}
@@ -496,9 +496,9 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
struct virSecretCountData data = {
.conn = conn, .filter = filter, .count = 0 };
- virObjectLock(secrets);
+ virObjectRWLockRead(secrets);
virHashForEach(secrets->objs, virSecretObjListNumOfSecretsCallback, &data);
- virObjectUnlock(secrets);
+ virObjectRWUnlock(secrets);
return data.count;
}
@@ -595,15 +595,15 @@ virSecretObjListExport(virConnectPtr conn,
.filter = filter, .flags = flags,
.nsecrets = 0, .error = false };
- virObjectLock(secretobjs);
+ virObjectRWLockRead(secretobjs);
if (secrets &&
VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0) {
- virObjectUnlock(secretobjs);
+ virObjectRWUnlock(secretobjs);
return -1;
}
virHashForEach(secretobjs->objs, virSecretObjListExportCallback, &data);
- virObjectUnlock(secretobjs);
+ virObjectRWUnlock(secretobjs);
if (data.error)
goto error;
@@ -633,9 +633,9 @@ virSecretObjListGetUUIDs(virSecretObjListPtr secrets,
.conn = conn, .filter = filter, .uuids = uuids, .nuuids = 0,
.maxuuids = maxuuids, .error = false };
- virObjectLock(secrets);
+ virObjectRWLockRead(secrets);
virHashForEach(secrets->objs, virSecretObjListGetUUIDsCallback, &data);
- virObjectUnlock(secrets);
+ virObjectRWUnlock(secrets);
if (data.error)
goto error;
--
2.13.6