util: Rename virObjectLockRead to virObjectRWLockRead

Since the class it represents is based on virObjectRWLockableClass
and in order to make sure we differentiate just in case anyone somehow
believes they could use virObjectLockRead for a virObjectLockableClass,
let's rename the API to use the RW in the name. Besides the RW locks
refer to pthread_rwlock_{init|rdlock|wrlock|unlock|destroy} while the
other locks refer to pthread_mutex_{init|lock|unlock|destroy}.

Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2017-07-28 09:57:04 -04:00
parent 40cc355c92
commit 99a72b3eb4
4 changed files with 19 additions and 14 deletions

View File

@ -118,7 +118,7 @@ virDomainObjListFindByIDInternal(virDomainObjListPtr doms,
bool ref) bool ref)
{ {
virDomainObjPtr obj; virDomainObjPtr obj;
virObjectLockRead(doms); virObjectRWLockRead(doms);
obj = virHashSearch(doms->objs, virDomainObjListSearchID, &id, NULL); obj = virHashSearch(doms->objs, virDomainObjListSearchID, &id, NULL);
if (ref) { if (ref) {
virObjectRef(obj); virObjectRef(obj);
@ -160,7 +160,7 @@ virDomainObjListFindByUUIDInternal(virDomainObjListPtr doms,
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virDomainObjPtr obj; virDomainObjPtr obj;
virObjectLockRead(doms); virObjectRWLockRead(doms);
virUUIDFormat(uuid, uuidstr); virUUIDFormat(uuid, uuidstr);
obj = virHashLookup(doms->objs, uuidstr); obj = virHashLookup(doms->objs, uuidstr);
@ -204,7 +204,7 @@ virDomainObjPtr virDomainObjListFindByName(virDomainObjListPtr doms,
{ {
virDomainObjPtr obj; virDomainObjPtr obj;
virObjectLockRead(doms); virObjectRWLockRead(doms);
obj = virHashLookup(doms->objsName, name); obj = virHashLookup(doms->objsName, name);
virObjectRef(obj); virObjectRef(obj);
virObjectUnlock(doms); virObjectUnlock(doms);
@ -653,7 +653,7 @@ virDomainObjListNumOfDomains(virDomainObjListPtr doms,
virConnectPtr conn) virConnectPtr conn)
{ {
struct virDomainObjListData data = { filter, conn, active, 0 }; struct virDomainObjListData data = { filter, conn, active, 0 };
virObjectLockRead(doms); virObjectRWLockRead(doms);
virHashForEach(doms->objs, virDomainObjListCount, &data); virHashForEach(doms->objs, virDomainObjListCount, &data);
virObjectUnlock(doms); virObjectUnlock(doms);
return data.count; return data.count;
@ -697,7 +697,7 @@ virDomainObjListGetActiveIDs(virDomainObjListPtr doms,
{ {
struct virDomainIDData data = { filter, conn, struct virDomainIDData data = { filter, conn,
0, maxids, ids }; 0, maxids, ids };
virObjectLockRead(doms); virObjectRWLockRead(doms);
virHashForEach(doms->objs, virDomainObjListCopyActiveIDs, &data); virHashForEach(doms->objs, virDomainObjListCopyActiveIDs, &data);
virObjectUnlock(doms); virObjectUnlock(doms);
return data.numids; return data.numids;
@ -751,7 +751,7 @@ virDomainObjListGetInactiveNames(virDomainObjListPtr doms,
struct virDomainNameData data = { filter, conn, struct virDomainNameData data = { filter, conn,
0, 0, maxnames, names }; 0, 0, maxnames, names };
size_t i; size_t i;
virObjectLockRead(doms); virObjectRWLockRead(doms);
virHashForEach(doms->objs, virDomainObjListCopyInactiveNames, &data); virHashForEach(doms->objs, virDomainObjListCopyInactiveNames, &data);
virObjectUnlock(doms); virObjectUnlock(doms);
if (data.oom) { if (data.oom) {
@ -792,7 +792,7 @@ virDomainObjListForEach(virDomainObjListPtr doms,
struct virDomainListIterData data = { struct virDomainListIterData data = {
callback, opaque, 0, callback, opaque, 0,
}; };
virObjectLockRead(doms); virObjectRWLockRead(doms);
virHashForEach(doms->objs, virDomainObjListHelper, &data); virHashForEach(doms->objs, virDomainObjListHelper, &data);
virObjectUnlock(doms); virObjectUnlock(doms);
return data.ret; return data.ret;
@ -925,7 +925,7 @@ virDomainObjListCollect(virDomainObjListPtr domlist,
{ {
struct virDomainListData data = { NULL, 0 }; struct virDomainListData data = { NULL, 0 };
virObjectLockRead(domlist); virObjectRWLockRead(domlist);
sa_assert(domlist->objs); sa_assert(domlist->objs);
if (VIR_ALLOC_N(data.vms, virHashSize(domlist->objs)) < 0) { if (VIR_ALLOC_N(data.vms, virHashSize(domlist->objs)) < 0) {
virObjectUnlock(domlist); virObjectUnlock(domlist);
@ -962,7 +962,7 @@ virDomainObjListConvert(virDomainObjListPtr domlist,
*nvms = 0; *nvms = 0;
*vms = NULL; *vms = NULL;
virObjectLockRead(domlist); virObjectRWLockRead(domlist);
for (i = 0; i < ndoms; i++) { for (i = 0; i < ndoms; i++) {
virDomainPtr dom = doms[i]; virDomainPtr dom = doms[i];

View File

@ -2308,10 +2308,10 @@ virObjectListFree;
virObjectListFreeCount; virObjectListFreeCount;
virObjectLock; virObjectLock;
virObjectLockableNew; virObjectLockableNew;
virObjectLockRead;
virObjectNew; virObjectNew;
virObjectRef; virObjectRef;
virObjectRWLockableNew; virObjectRWLockableNew;
virObjectRWLockRead;
virObjectUnlock; virObjectUnlock;
virObjectUnref; virObjectUnref;

View File

@ -399,7 +399,7 @@ virObjectLock(void *anyobj)
/** /**
* virObjectLockRead: * virObjectRWLockRead:
* @anyobj: any instance of virObjectRWLockable * @anyobj: any instance of virObjectRWLockable
* *
* Acquire a read lock on @anyobj. The lock must be * Acquire a read lock on @anyobj. The lock must be
@ -409,9 +409,14 @@ virObjectLock(void *anyobj)
* on the object before locking it (eg virObjectRef). * on the object before locking it (eg virObjectRef).
* The object must be unlocked before releasing this * The object must be unlocked before releasing this
* reference. * reference.
*
* NB: It's possible to return without the lock if
* @anyobj was invalid - this has been considered
* a programming error rather than something that
* should be checked.
*/ */
void void
virObjectLockRead(void *anyobj) virObjectRWLockRead(void *anyobj)
{ {
if (virObjectIsClass(anyobj, virObjectRWLockableClass)) { if (virObjectIsClass(anyobj, virObjectRWLockableClass)) {
virObjectRWLockablePtr obj = anyobj; virObjectRWLockablePtr obj = anyobj;
@ -429,7 +434,7 @@ virObjectLockRead(void *anyobj)
* @anyobj: any instance of virObjectLockable or virObjectRWLockable * @anyobj: any instance of virObjectLockable or virObjectRWLockable
* *
* Release a lock on @anyobj. The lock must have been acquired by * Release a lock on @anyobj. The lock must have been acquired by
* virObjectLock or virObjectLockRead. * virObjectLock or virObjectRWLockRead.
*/ */
void void
virObjectUnlock(void *anyobj) virObjectUnlock(void *anyobj)

View File

@ -125,7 +125,7 @@ virObjectLock(void *lockableobj)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
void void
virObjectLockRead(void *lockableobj) virObjectRWLockRead(void *lockableobj)
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
void void