[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libvir] [patch 8/9] Some src/hash.c re-factoring



Re-name virConnect->domains_mux to virConnect->hashes_mux
since it will also be used to protect the networks hash.

Signed-off-by: Mark McLoughlin <markmc redhat com>

Index: libvirt/src/hash.c
===================================================================
--- libvirt.orig/src/hash.c
+++ libvirt/src/hash.c
@@ -660,8 +660,8 @@ virGetConnect(void) {
     ret->domains = virHashCreate(20);
     if (ret->domains == NULL)
         goto failed;
-    ret->domains_mux = xmlNewMutex();
-    if (ret->domains_mux == NULL)
+    ret->hashes_mux = xmlNewMutex();
+    if (ret->hashes_mux == NULL)
         goto failed;
 
     ret->uses = 1;
@@ -671,8 +671,8 @@ failed:
     if (ret != NULL) {
 	if (ret->domains != NULL)
 	    virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName);
-	if (ret->domains_mux != NULL)
-	    xmlFreeMutex(ret->domains_mux);
+	if (ret->hashes_mux != NULL)
+	    xmlFreeMutex(ret->hashes_mux);
         free(ret);
     }
     return(NULL);
@@ -691,22 +691,22 @@ int	
 virFreeConnect(virConnectPtr conn) {
     int ret;
 
-    if ((!VIR_IS_CONNECT(conn)) || (conn->domains_mux == NULL)) {
+    if ((!VIR_IS_CONNECT(conn)) || (conn->hashes_mux == NULL)) {
         virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
         return(-1);
     }
-    xmlMutexLock(conn->domains_mux);
+    xmlMutexLock(conn->hashes_mux);
     conn->uses--;
     ret = conn->uses;
     if (ret > 0) {
-	xmlMutexUnlock(conn->domains_mux);
+	xmlMutexUnlock(conn->hashes_mux);
 	return(ret);
     }
 
     if (conn->domains != NULL)
         virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
-    if (conn->domains_mux != NULL)
-        xmlFreeMutex(conn->domains_mux);
+    if (conn->hashes_mux != NULL)
+        xmlFreeMutex(conn->hashes_mux);
     free(conn);
     return(0);
 }
@@ -729,11 +729,11 @@ virGetDomain(virConnectPtr conn, const c
     virDomainPtr ret = NULL;
 
     if ((!VIR_IS_CONNECT(conn)) || ((name == NULL) && (uuid == NULL)) ||
-        (conn->domains_mux == NULL)) {
+        (conn->hashes_mux == NULL)) {
         virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
         return(NULL);
     }
-    xmlMutexLock(conn->domains_mux);
+    xmlMutexLock(conn->hashes_mux);
 
     /* TODO search by UUID first as they are better differenciators */
 
@@ -771,11 +771,11 @@ virGetDomain(virConnectPtr conn, const c
     conn->uses++;
 done:
     ret->uses++;
-    xmlMutexUnlock(conn->domains_mux);
+    xmlMutexUnlock(conn->hashes_mux);
     return(ret);
 
 error:
-    xmlMutexUnlock(conn->domains_mux);
+    xmlMutexUnlock(conn->hashes_mux);
     if (ret != NULL) {
 	if (ret->name != NULL)
 	    free(ret->name );
@@ -799,11 +799,11 @@ virFreeDomain(virConnectPtr conn, virDom
     int ret = 0;
 
     if ((!VIR_IS_CONNECT(conn)) || (!VIR_IS_CONNECTED_DOMAIN(domain)) ||
-        (domain->conn != conn) || (conn->domains_mux == NULL)) {
+        (domain->conn != conn) || (conn->hashes_mux == NULL)) {
         virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
         return(-1);
     }
-    xmlMutexLock(conn->domains_mux);
+    xmlMutexLock(conn->hashes_mux);
 
     /*
      * decrement the count for the domain
@@ -839,13 +839,13 @@ virFreeDomain(virConnectPtr conn, virDom
     
     if (conn->domains != NULL)
         virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
-    if (conn->domains_mux != NULL)
-        xmlFreeMutex(conn->domains_mux);
+    if (conn->hashes_mux != NULL)
+        xmlFreeMutex(conn->hashes_mux);
     free(conn);
     return(0);
 
 done:
-    xmlMutexUnlock(conn->domains_mux);
+    xmlMutexUnlock(conn->hashes_mux);
     return(ret);
 }
 
@@ -870,7 +870,7 @@ virGetDomainByID(virConnectPtr conn, int
         virHashError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
         return(NULL);
     }
-    xmlMutexLock(conn->domains_mux);
+    xmlMutexLock(conn->hashes_mux);
 
     table = conn->domains;
     if ((table == NULL) || (table->nbElems == 0))
@@ -890,7 +890,7 @@ virGetDomainByID(virConnectPtr conn, int
 	}
     }
 done:
-    xmlMutexUnlock(conn->domains_mux);
+    xmlMutexUnlock(conn->hashes_mux);
     return(ret);
 }
 /*
Index: libvirt/src/internal.h
===================================================================
--- libvirt.orig/src/internal.h
+++ libvirt/src/internal.h
@@ -125,7 +125,7 @@ struct _virConnect {
     void *userData;         /* the user data */
 
     /* misc */
-    xmlMutexPtr domains_mux;/* a mutex to protect the domain hash table */
+    xmlMutexPtr hashes_mux;/* a mutex to protect the domain hash table */
     virHashTablePtr domains;/* hash table for known domains */
     int flags;              /* a set of connection flags */
 };

-- 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]