提交 3dcab1de 编写于 作者: J John Ferlan

network: Convert virNetworkObjList to use RWObjectLockable

Let's use the RWObjectLockable for the various list lock mgmt.
Only time need Write lock will be for Add, Remove, and Prune logic.
上级 0c691e98
...@@ -61,7 +61,7 @@ struct _virNetworkObj { ...@@ -61,7 +61,7 @@ struct _virNetworkObj {
}; };
struct _virNetworkObjList { struct _virNetworkObjList {
virObjectLockable parent; virObjectRWLockable parent;
virHashTablePtr objs; virHashTablePtr objs;
}; };
...@@ -80,7 +80,7 @@ virNetworkObjOnceInit(void) ...@@ -80,7 +80,7 @@ virNetworkObjOnceInit(void)
virNetworkObjDispose))) virNetworkObjDispose)))
return -1; return -1;
if (!(virNetworkObjListClass = virClassNew(virClassForObjectLockable(), if (!(virNetworkObjListClass = virClassNew(virClassForObjectRWLockable(),
"virNetworkObjList", "virNetworkObjList",
sizeof(virNetworkObjList), sizeof(virNetworkObjList),
virNetworkObjListDispose))) virNetworkObjListDispose)))
...@@ -337,7 +337,7 @@ virNetworkObjListNew(void) ...@@ -337,7 +337,7 @@ virNetworkObjListNew(void)
if (virNetworkObjInitialize() < 0) if (virNetworkObjInitialize() < 0)
return NULL; return NULL;
if (!(nets = virObjectLockableNew(virNetworkObjListClass))) if (!(nets = virObjectRWLockableNew(virNetworkObjListClass)))
return NULL; return NULL;
if (!(nets->objs = virHashCreate(50, virObjectFreeHashData))) { if (!(nets->objs = virHashCreate(50, virObjectFreeHashData))) {
...@@ -381,9 +381,9 @@ virNetworkObjFindByUUID(virNetworkObjListPtr nets, ...@@ -381,9 +381,9 @@ virNetworkObjFindByUUID(virNetworkObjListPtr nets,
{ {
virNetworkObjPtr obj; virNetworkObjPtr obj;
virObjectLock(nets); virObjectRWLockRead(nets);
obj = virNetworkObjFindByUUIDLocked(nets, uuid); obj = virNetworkObjFindByUUIDLocked(nets, uuid);
virObjectUnlock(nets); virObjectRWUnlock(nets);
if (obj) if (obj)
virObjectLock(obj); virObjectLock(obj);
return obj; return obj;
...@@ -435,9 +435,9 @@ virNetworkObjFindByName(virNetworkObjListPtr nets, ...@@ -435,9 +435,9 @@ virNetworkObjFindByName(virNetworkObjListPtr nets,
{ {
virNetworkObjPtr obj; virNetworkObjPtr obj;
virObjectLock(nets); virObjectRWLockRead(nets);
obj = virNetworkObjFindByNameLocked(nets, name); obj = virNetworkObjFindByNameLocked(nets, name);
virObjectUnlock(nets); virObjectRWUnlock(nets);
if (obj) if (obj)
virObjectLock(obj); virObjectLock(obj);
return obj; return obj;
...@@ -638,9 +638,9 @@ virNetworkObjAssignDef(virNetworkObjListPtr nets, ...@@ -638,9 +638,9 @@ virNetworkObjAssignDef(virNetworkObjListPtr nets,
{ {
virNetworkObjPtr obj; virNetworkObjPtr obj;
virObjectLock(nets); virObjectRWLockWrite(nets);
obj = virNetworkObjAssignDefLocked(nets, def, flags); obj = virNetworkObjAssignDefLocked(nets, def, flags);
virObjectUnlock(nets); virObjectRWUnlock(nets);
return obj; return obj;
} }
...@@ -789,10 +789,10 @@ virNetworkObjRemoveInactive(virNetworkObjListPtr nets, ...@@ -789,10 +789,10 @@ virNetworkObjRemoveInactive(virNetworkObjListPtr nets,
virUUIDFormat(obj->def->uuid, uuidstr); virUUIDFormat(obj->def->uuid, uuidstr);
virObjectRef(obj); virObjectRef(obj);
virObjectUnlock(obj); virObjectUnlock(obj);
virObjectLock(nets); virObjectRWLockWrite(nets);
virObjectLock(obj); virObjectLock(obj);
virHashRemoveEntry(nets->objs, uuidstr); virHashRemoveEntry(nets->objs, uuidstr);
virObjectUnlock(nets); virObjectRWUnlock(nets);
virObjectUnref(obj); virObjectUnref(obj);
} }
...@@ -1180,9 +1180,9 @@ virNetworkObjBridgeInUse(virNetworkObjListPtr nets, ...@@ -1180,9 +1180,9 @@ virNetworkObjBridgeInUse(virNetworkObjListPtr nets,
virNetworkObjPtr obj; virNetworkObjPtr obj;
struct virNetworkObjBridgeInUseHelperData data = {bridge, skipname}; struct virNetworkObjBridgeInUseHelperData data = {bridge, skipname};
virObjectLock(nets); virObjectRWLockRead(nets);
obj = virHashSearch(nets->objs, virNetworkObjBridgeInUseHelper, &data, NULL); obj = virHashSearch(nets->objs, virNetworkObjBridgeInUseHelper, &data, NULL);
virObjectUnlock(nets); virObjectRWUnlock(nets);
return obj != NULL; return obj != NULL;
} }
...@@ -1369,7 +1369,7 @@ virNetworkObjListExport(virConnectPtr conn, ...@@ -1369,7 +1369,7 @@ virNetworkObjListExport(virConnectPtr conn,
.conn = conn, .nets = NULL, .filter = filter, .flags = flags, .conn = conn, .nets = NULL, .filter = filter, .flags = flags,
.nnets = 0, .error = false }; .nnets = 0, .error = false };
virObjectLock(netobjs); virObjectRWLockRead(netobjs);
if (nets && VIR_ALLOC_N(data.nets, virHashSize(netobjs->objs) + 1) < 0) if (nets && VIR_ALLOC_N(data.nets, virHashSize(netobjs->objs) + 1) < 0)
goto cleanup; goto cleanup;
...@@ -1387,7 +1387,7 @@ virNetworkObjListExport(virConnectPtr conn, ...@@ -1387,7 +1387,7 @@ virNetworkObjListExport(virConnectPtr conn,
ret = data.nnets; ret = data.nnets;
cleanup: cleanup:
virObjectUnlock(netobjs); virObjectRWUnlock(netobjs);
while (data.nets && data.nnets) while (data.nets && data.nnets)
virObjectUnref(data.nets[--data.nnets]); virObjectUnref(data.nets[--data.nnets]);
...@@ -1435,9 +1435,9 @@ virNetworkObjListForEach(virNetworkObjListPtr nets, ...@@ -1435,9 +1435,9 @@ virNetworkObjListForEach(virNetworkObjListPtr nets,
{ {
struct virNetworkObjListForEachHelperData data = { struct virNetworkObjListForEachHelperData data = {
.callback = callback, .opaque = opaque, .ret = 0}; .callback = callback, .opaque = opaque, .ret = 0};
virObjectLock(nets); virObjectRWLockRead(nets);
virHashForEach(nets->objs, virNetworkObjListForEachHelper, &data); virHashForEach(nets->objs, virNetworkObjListForEachHelper, &data);
virObjectUnlock(nets); virObjectRWUnlock(nets);
return data.ret; return data.ret;
} }
...@@ -1503,9 +1503,9 @@ virNetworkObjListGetNames(virNetworkObjListPtr nets, ...@@ -1503,9 +1503,9 @@ virNetworkObjListGetNames(virNetworkObjListPtr nets,
.conn = conn, .filter = filter, .names = names, .nnames = 0, .conn = conn, .filter = filter, .names = names, .nnames = 0,
.maxnames = maxnames, .active = active, .error = false}; .maxnames = maxnames, .active = active, .error = false};
virObjectLock(nets); virObjectRWLockRead(nets);
virHashForEach(nets->objs, virNetworkObjListGetHelper, &data); virHashForEach(nets->objs, virNetworkObjListGetHelper, &data);
virObjectUnlock(nets); virObjectRWUnlock(nets);
if (data.error) if (data.error)
goto cleanup; goto cleanup;
...@@ -1530,9 +1530,9 @@ virNetworkObjListNumOfNetworks(virNetworkObjListPtr nets, ...@@ -1530,9 +1530,9 @@ virNetworkObjListNumOfNetworks(virNetworkObjListPtr nets,
.conn = conn, .filter = filter, .names = NULL, .nnames = 0, .conn = conn, .filter = filter, .names = NULL, .nnames = 0,
.maxnames = -1, .active = active, .error = false}; .maxnames = -1, .active = active, .error = false};
virObjectLock(nets); virObjectRWLockRead(nets);
virHashForEach(nets->objs, virNetworkObjListGetHelper, &data); virHashForEach(nets->objs, virNetworkObjListGetHelper, &data);
virObjectUnlock(nets); virObjectRWUnlock(nets);
return data.nnames; return data.nnames;
} }
...@@ -1572,7 +1572,7 @@ virNetworkObjListPrune(virNetworkObjListPtr nets, ...@@ -1572,7 +1572,7 @@ virNetworkObjListPrune(virNetworkObjListPtr nets,
{ {
struct virNetworkObjListPruneHelperData data = {flags}; struct virNetworkObjListPruneHelperData data = {flags};
virObjectLock(nets); virObjectRWLockWrite(nets);
virHashRemoveSet(nets->objs, virNetworkObjListPruneHelper, &data); virHashRemoveSet(nets->objs, virNetworkObjListPruneHelper, &data);
virObjectUnlock(nets); virObjectRWUnlock(nets);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册