[PATCH 21/43] node_device: convert virMutex to GMutex

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/conf/virnodedeviceobj.h          |  4 ++--
 src/node_device/node_device_driver.c | 11 +++--------
 src/node_device/node_device_hal.c    | 20 +++++---------------
 src/node_device/node_device_udev.c   | 21 +++++----------------
 4 files changed, 15 insertions(+), 41 deletions(-)

diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h
index c9df8dedab..2ffefddd20 100644
--- a/src/conf/virnodedeviceobj.h
+++ b/src/conf/virnodedeviceobj.h
@@ -35,8 +35,8 @@ typedef virNodeDeviceObjList *virNodeDeviceObjListPtr;
 typedef struct _virNodeDeviceDriverState virNodeDeviceDriverState;
 typedef virNodeDeviceDriverState *virNodeDeviceDriverStatePtr;
 struct _virNodeDeviceDriverState {
-    virMutex lock;
-    virCond initCond;
+    GMutex lock;
+    GCond initCond;
     bool initialized;
 
     /* pid file FD, ensures two copies of the driver can't use the same root */
diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c
index ee175e1095..7d626948ec 100644
--- a/src/node_device/node_device_driver.c
+++ b/src/node_device/node_device_driver.c
@@ -145,14 +145,14 @@ nodeDeviceUpdateDriverName(virNodeDeviceDefPtr def G_GNUC_UNUSED)
 void
 nodeDeviceLock(void)
 {
-    virMutexLock(&driver->lock);
+    g_mutex_lock(&driver->lock);
 }
 
 
 void
 nodeDeviceUnlock(void)
 {
-    virMutexUnlock(&driver->lock);
+    g_mutex_unlock(&driver->lock);
 }
 
 
@@ -161,12 +161,7 @@ nodeDeviceWaitInit(void)
 {
     nodeDeviceLock();
     while (!driver->initialized) {
-        if (virCondWait(&driver->initCond, &driver->lock) < 0) {
-            virReportSystemError(errno, "%s",
-                                 _("failed to wait on condition"));
-            nodeDeviceUnlock();
-            return -1;
-        }
+        g_cond_wait(&driver->initCond, &driver->lock);
     }
     nodeDeviceUnlock();
     return 0;
diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index 53a49ba2aa..fe78c3c4ae 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -607,18 +607,8 @@ nodeStateInitialize(bool privileged G_GNUC_UNUSED,
         return VIR_DRV_STATE_INIT_ERROR;
 
     driver->lockFD = -1;
-    if (virMutexInit(&driver->lock) < 0) {
-        VIR_FREE(driver);
-        return VIR_DRV_STATE_INIT_ERROR;
-    }
-
-    if (virCondInit(&driver->initCond) < 0) {
-        virReportSystemError(errno, "%s",
-                             _("Unable to initialize condition variable"));
-        virMutexDestroy(&driver->lock);
-        VIR_FREE(driver);
-        return VIR_DRV_STATE_INIT_ERROR;
-    }
+    g_mutex_init(&driver->lock);
+    g_cond_init(&driver->initCond);
 
     nodeDeviceLock();
 
@@ -713,7 +703,7 @@ nodeStateInitialize(bool privileged G_GNUC_UNUSED,
     nodeDeviceLock();
     driver->initialized = true;
     nodeDeviceUnlock();
-    virCondBroadcast(&driver->initCond);
+    g_cond_broadcast(&driver->initCond);
 
     return VIR_DRV_STATE_INIT_COMPLETE;
 
@@ -747,8 +737,8 @@ nodeStateCleanup(void)
 
         VIR_FREE(driver->stateDir);
         nodeDeviceUnlock();
-        virCondDestroy(&driver->initCond);
-        virMutexDestroy(&driver->lock);
+        g_cond_clear(&driver->initCond);
+        g_mutex_clear(&driver->lock);
         VIR_FREE(driver);
         return 0;
     }
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 8451903e8a..433de0aae0 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1477,8 +1477,8 @@ nodeStateCleanup(void)
         virPidFileRelease(driver->stateDir, "driver", driver->lockFD);
 
     VIR_FREE(driver->stateDir);
-    virCondDestroy(&driver->initCond);
-    virMutexDestroy(&driver->lock);
+    g_cond_clear(&driver->initCond);
+    g_mutex_clear(&driver->lock);
     VIR_FREE(driver);
 
     udevPCITranslateDeinit();
@@ -1748,7 +1748,7 @@ nodeStateInitializeEnumerate(void *opaque)
     nodeDeviceLock();
     driver->initialized = true;
     nodeDeviceUnlock();
-    virCondBroadcast(&driver->initCond);
+    g_cond_broadcast(&driver->initCond);
 
     return;
 
@@ -1806,19 +1806,8 @@ nodeStateInitialize(bool privileged,
         return VIR_DRV_STATE_INIT_ERROR;
 
     driver->lockFD = -1;
-    if (virMutexInit(&driver->lock) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("Unable to initialize mutex"));
-        VIR_FREE(driver);
-        return VIR_DRV_STATE_INIT_ERROR;
-    }
-    if (virCondInit(&driver->initCond) < 0) {
-        virReportSystemError(errno, "%s",
-                             _("Unable to initialize condition variable"));
-        virMutexDestroy(&driver->lock);
-        VIR_FREE(driver);
-        return VIR_DRV_STATE_INIT_ERROR;
-    }
+    g_mutex_init(&driver->lock);
+    g_cond_init(&driver->initCond);
 
     driver->privileged = privileged;
 
-- 
2.25.2






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux