[PATCH 19/43] lxc: convert virMutex to GMutex

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/lxc/lxc_conf.h       |  6 +++---
 src/lxc/lxc_controller.c | 25 ++++++++++---------------
 src/lxc/lxc_driver.c     |  7 ++-----
 tests/testutilslxc.c     |  9 ++-------
 4 files changed, 17 insertions(+), 30 deletions(-)

diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index f2f0e0a570..27cb861c08 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -64,7 +64,7 @@ struct _virLXCDriverConfig {
 };
 
 struct _virLXCDriver {
-    virMutex lock;
+    GMutex lock;
 
     /* Require lock to get reference on 'config',
      * then lockless thereafter */
@@ -116,9 +116,9 @@ virDomainXMLOptionPtr lxcDomainXMLConfInit(virLXCDriverPtr driver);
 
 static inline void lxcDriverLock(virLXCDriverPtr driver)
 {
-    virMutexLock(&driver->lock);
+    g_mutex_lock(&driver->lock);
 }
 static inline void lxcDriverUnlock(virLXCDriverPtr driver)
 {
-    virMutexUnlock(&driver->lock);
+    g_mutex_unlock(&driver->lock);
 }
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 453b435dd6..f7394c53a6 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -161,12 +161,7 @@ virLXCControllerDriverNew(void)
 {
     virLXCDriverPtr driver = g_new0(virLXCDriver, 1);
 
-    if (virMutexInit(&driver->lock) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("cannot initialize mutex"));
-        g_free(driver);
-        return NULL;
-    }
+    g_mutex_init(&driver->lock);
 
     driver->caps = virLXCDriverCapsInit(NULL);
     driver->xmlopt = lxcDomainXMLConfInit(driver);
@@ -182,7 +177,7 @@ virLXCControllerDriverFree(virLXCDriverPtr driver)
         return;
     virObjectUnref(driver->xmlopt);
     virObjectUnref(driver->caps);
-    virMutexDestroy(&driver->lock);
+    g_mutex_clear(&driver->lock);
     g_free(driver);
 }
 
@@ -1034,7 +1029,7 @@ static int lxcControllerClearCapabilities(void)
 }
 
 static bool wantReboot;
-static virMutex lock = VIR_MUTEX_INITIALIZER;
+G_LOCK_DEFINE_STATIC(lock);
 
 
 static void virLXCControllerSignalChildIO(virNetDaemonPtr dmn,
@@ -1049,13 +1044,13 @@ static void virLXCControllerSignalChildIO(virNetDaemonPtr dmn,
     VIR_DEBUG("Got sig child %d vs %lld", ret, (long long)ctrl->initpid);
     if (ret == ctrl->initpid) {
         virNetDaemonQuit(dmn);
-        virMutexLock(&lock);
+        G_LOCK(lock);
         if (WIFSIGNALED(status) &&
             WTERMSIG(status) == SIGHUP) {
             VIR_DEBUG("Status indicates reboot");
             wantReboot = true;
         }
-        virMutexUnlock(&lock);
+        G_UNLOCK(lock);
     }
 }
 
@@ -1169,7 +1164,7 @@ static void virLXCControllerConsoleEPoll(int watch, int fd, int events, void *op
 {
     virLXCControllerConsolePtr console = opaque;
 
-    virMutexLock(&lock);
+    G_LOCK(lock);
     VIR_DEBUG("IO event watch=%d fd=%d events=%d fromHost=%zu fromcont=%zu",
               watch, fd, events,
               console->fromHostLen,
@@ -1209,14 +1204,14 @@ static void virLXCControllerConsoleEPoll(int watch, int fd, int events, void *op
     }
 
  cleanup:
-    virMutexUnlock(&lock);
+    G_UNLOCK(lock);
 }
 
 static void virLXCControllerConsoleIO(int watch, int fd, int events, void *opaque)
 {
     virLXCControllerConsolePtr console = opaque;
 
-    virMutexLock(&lock);
+    G_LOCK(lock);
     VIR_DEBUG("IO event watch=%d fd=%d events=%d fromHost=%zu fromcont=%zu",
               watch, fd, events,
               console->fromHostLen,
@@ -1290,7 +1285,7 @@ static void virLXCControllerConsoleIO(int watch, int fd, int events, void *opaqu
     }
 
     virLXCControllerConsoleUpdateWatch(console);
-    virMutexUnlock(&lock);
+    G_UNLOCK(lock);
     return;
 
  error:
@@ -1298,7 +1293,7 @@ static void virLXCControllerConsoleIO(int watch, int fd, int events, void *opaqu
     virEventRemoveHandle(console->hostWatch);
     console->contWatch = console->hostWatch = -1;
     virNetDaemonQuit(console->daemon);
-    virMutexUnlock(&lock);
+    G_UNLOCK(lock);
 }
 
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 7b232b4bac..3253c08117 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1494,10 +1494,7 @@ static int lxcStateInitialize(bool privileged,
     if (VIR_ALLOC(lxc_driver) < 0)
         return VIR_DRV_STATE_INIT_ERROR;
     lxc_driver->lockFD = -1;
-    if (virMutexInit(&lxc_driver->lock) < 0) {
-        VIR_FREE(lxc_driver);
-        return VIR_DRV_STATE_INIT_ERROR;
-    }
+    g_mutex_init(&lxc_driver->lock);
 
     if (!(lxc_driver->domains = virDomainObjListNew()))
         goto cleanup;
@@ -1631,7 +1628,7 @@ static int lxcStateCleanup(void)
         virPidFileRelease(lxc_driver->config->stateDir, "driver", lxc_driver->lockFD);
 
     virObjectUnref(lxc_driver->config);
-    virMutexDestroy(&lxc_driver->lock);
+    g_mutex_clear(&lxc_driver->lock);
     VIR_FREE(lxc_driver);
 
     return 0;
diff --git a/tests/testutilslxc.c b/tests/testutilslxc.c
index b5e2f542e7..1e04263d1f 100644
--- a/tests/testutilslxc.c
+++ b/tests/testutilslxc.c
@@ -63,12 +63,7 @@ testLXCDriverInit(void)
 {
     virLXCDriverPtr driver = g_new0(virLXCDriver, 1);
 
-    if (virMutexInit(&driver->lock) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", "cannot initialize mutex");
-        g_free(driver);
-        return NULL;
-    }
+    g_mutex_init(&driver->lock);
 
     driver->caps = testLXCCapsInit();
     driver->xmlopt = lxcDomainXMLConfInit(driver);
@@ -82,7 +77,7 @@ testLXCDriverFree(virLXCDriverPtr driver)
 {
     virObjectUnref(driver->xmlopt);
     virObjectUnref(driver->caps);
-    virMutexDestroy(&driver->lock);
+    g_mutex_clear(&driver->lock);
     g_free(driver);
 }
 
-- 
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