]> xenbits.xensource.com Git - libvirt.git/commitdiff
lxc: Use atomic ops for driver->nactive
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 16 Jul 2013 17:05:06 +0000 (19:05 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 18 Jul 2013 12:16:54 +0000 (14:16 +0200)
src/lxc/lxc_conf.h
src/lxc/lxc_process.c

index 8ad925803b77a3462fc147a06a0bd9c6c61c97cb..d935064aa82a141efefd8095b310f1ce9e9aa913 100644 (file)
@@ -75,7 +75,7 @@ struct _virLXCDriver {
 
     virSysinfoDefPtr hostsysinfo;
 
-    size_t nactive;
+    unsigned int nactive;
 
     virStateInhibitCallback inhibitCallback;
     void *inhibitOpaque;
index 233ac3c52c9ec8dc2b623764c422e6991578cb6d..4ad69ffc1fcfd7b689cefcedd2a6ad900262b5c3 100644 (file)
@@ -48,6 +48,7 @@
 #include "lxc_hostdev.h"
 #include "virhook.h"
 #include "virstring.h"
+#include "viratomic.h"
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
@@ -257,8 +258,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);
@@ -1284,9 +1284,8 @@ int virLXCProcessStart(virConnectPtr conn,
     virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
     priv->doneStopEvent = false;
 
-    if (!driver->nactive && driver->inhibitCallback)
+    if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback)
         driver->inhibitCallback(true, driver->inhibitOpaque);
-    driver->nactive++;
 
     if (lxcContainerWaitForContinue(handshakefds[0]) < 0) {
         char out[1024];
@@ -1470,9 +1469,8 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
         virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
                              VIR_DOMAIN_RUNNING_UNKNOWN);
 
-        if (!driver->nactive && driver->inhibitCallback)
+        if (virAtomicIntInc(&driver->nactive) == 1 && driver->inhibitCallback)
             driver->inhibitCallback(true, driver->inhibitOpaque);
-        driver->nactive++;
 
         if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))
             goto error;