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

[libvirt] [PATCH 3/9] lxc: Use atomic ops for driver->nactive



---
 src/lxc/lxc_conf.h    |  2 +-
 src/lxc/lxc_process.c | 10 ++++------
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h
index 6ca6198..f9a3e53 100644
--- a/src/lxc/lxc_conf.h
+++ b/src/lxc/lxc_conf.h
@@ -77,7 +77,7 @@ struct _virLXCDriver {
 
     virSysinfoDefPtr hostsysinfo;
 
-    size_t nactive;
+    unsigned int nactive;
 
     virStateInhibitCallback inhibitCallback;
     void *inhibitOpaque;
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 1024576..4b83729 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -48,6 +48,7 @@
 #include "lxc_hostdev.h"
 #include "virhook.h"
 #include "virstring.h"
+#include "viratomic.h"
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
@@ -256,8 +257,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
     vm->pid = -1;
     vm->def->id = -1;
 
-    driver->nactive--;
-    if (!driver->nactive && driver->inhibitCallback)
+    if (virAtomicIntDecAndTest(&driver->nactive) && driver->inhibitCallback)
         driver->inhibitCallback(false, driver->inhibitOpaque);
 
     virLXCDomainReAttachHostDevices(driver, vm->def);
@@ -1273,9 +1273,8 @@ int virLXCProcessStart(virConnectPtr conn,
     virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
     priv->doneStopEvent = false;
 
-    if (!driver->nactive && driver->inhibitCallback)
+    if (virAtomicIntInc(&driver->nactive) && driver->inhibitCallback)
         driver->inhibitCallback(true, driver->inhibitOpaque);
-    driver->nactive++;
 
     if (lxcContainerWaitForContinue(handshakefds[0]) < 0) {
         char out[1024];
@@ -1458,9 +1457,8 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
         virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
                              VIR_DOMAIN_RUNNING_UNKNOWN);
 
-        if (!driver->nactive && driver->inhibitCallback)
+        if (virAtomicIntInc(&driver->nactive) && driver->inhibitCallback)
             driver->inhibitCallback(true, driver->inhibitOpaque);
-        driver->nactive++;
 
         if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))
             goto error;
-- 
1.8.1.5


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