[PATCH 5/7] src: Replace virAtomicIntInc() with g_atomic_int_add()

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

 



Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/libxl/libxl_domain.c          |  2 +-
 src/libxl/libxl_driver.c          |  2 +-
 src/lxc/lxc_process.c             |  4 ++--
 src/nwfilter/nwfilter_dhcpsnoop.c | 10 +++++-----
 src/qemu/qemu_process.c           |  4 ++--
 src/test/test_driver.c            |  2 +-
 src/util/viratomic.h              | 11 -----------
 src/util/virobject.c              |  4 ++--
 src/util/virprocess.c             |  2 +-
 9 files changed, 15 insertions(+), 26 deletions(-)

diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index d63eca0bd6..8885af451f 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -1471,7 +1471,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
     if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
         goto destroy_dom;
 
-    if (virAtomicIntInc(&driver->nactive) == 0 && driver->inhibitCallback)
+    if (g_atomic_int_add(&driver->nactive, 1) == 0 && driver->inhibitCallback)
         driver->inhibitCallback(true, driver->inhibitOpaque);
 
     /* finally we can call the 'started' hook script if any */
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index da9a640db5..41cbb67e3a 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -446,7 +446,7 @@ libxlReconnectDomain(virDomainObjPtr vm,
         virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
                              VIR_DOMAIN_RUNNING_UNKNOWN);
 
-    if (virAtomicIntInc(&driver->nactive) == 0 && driver->inhibitCallback)
+    if (g_atomic_int_add(&driver->nactive, 1) == 0 && driver->inhibitCallback)
         driver->inhibitCallback(true, driver->inhibitOpaque);
 
     /* Enable domain death events */
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 2e860e2fae..2bb2216dc0 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -1468,7 +1468,7 @@ int virLXCProcessStart(virConnectPtr conn,
     if (virCommandHandshakeNotify(cmd) < 0)
         goto cleanup;
 
-    if (virAtomicIntInc(&driver->nactive) == 0 && driver->inhibitCallback)
+    if (g_atomic_int_add(&driver->nactive, 1) == 0 && driver->inhibitCallback)
         driver->inhibitCallback(true, driver->inhibitOpaque);
 
     if (lxcContainerWaitForContinue(handshakefds[0]) < 0) {
@@ -1670,7 +1670,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
         virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
                              VIR_DOMAIN_RUNNING_UNKNOWN);
 
-        if (virAtomicIntInc(&driver->nactive) == 0 && driver->inhibitCallback)
+        if (g_atomic_int_add(&driver->nactive, 1) == 0 && driver->inhibitCallback)
             driver->inhibitCallback(true, driver->inhibitOpaque);
 
         if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))
diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index b82779609d..f73913ec9e 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -541,7 +541,7 @@ virNWFilterSnoopReqLeaseTimerRun(virNWFilterSnoopReqPtr req)
 static void
 virNWFilterSnoopReqGet(virNWFilterSnoopReqPtr req)
 {
-    virAtomicIntInc(&req->refctr);
+    g_atomic_int_add(&req->refctr, 1);
 }
 
 /*
@@ -756,7 +756,7 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req,
     /* put the lease on the req's list */
     virNWFilterSnoopIPLeaseTimerAdd(pl);
 
-    virAtomicIntInc(&virNWFilterSnoopState.nLeases);
+    g_atomic_int_add(&virNWFilterSnoopState.nLeases, 1);
 
  exit:
     if (update_leasefile)
@@ -1172,7 +1172,7 @@ virNWFilterSnoopDHCPDecodeJobSubmit(virThreadPoolPtr pool,
     ret = virThreadPoolSendJob(pool, 0, job);
 
     if (ret == 0)
-        virAtomicIntInc(qCtr);
+        g_atomic_int_add(qCtr, 1);
     else
         VIR_FREE(job);
 
@@ -1649,7 +1649,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
 
     threadPuts = true;
 
-    virAtomicIntInc(&virNWFilterSnoopState.nThreads);
+    g_atomic_int_add(&virNWFilterSnoopState.nThreads, 1);
 
     req->threadkey = virNWFilterSnoopActivate(req);
     if (!req->threadkey) {
@@ -1777,7 +1777,7 @@ virNWFilterSnoopLeaseFileSave(virNWFilterSnoopIPLeasePtr ipl)
         goto err_exit;
 
     /* keep dead leases at < ~95% of file size */
-    if (virAtomicIntInc(&virNWFilterSnoopState.wLeases) >=
+    if (g_atomic_int_add(&virNWFilterSnoopState.wLeases, 1) >=
         g_atomic_int_get(&virNWFilterSnoopState.nLeases) * 20)
         virNWFilterSnoopLeaseFileLoad();   /* load & refresh lease file */
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 57a60c568a..20c4e3bb5d 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5571,7 +5571,7 @@ qemuProcessInit(virQEMUDriverPtr driver,
         qemuDomainSetFakeReboot(driver, vm, false);
         virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_STARTING_UP);
 
-        if (virAtomicIntInc(&driver->nactive) == 0 && driver->inhibitCallback)
+        if (g_atomic_int_add(&driver->nactive, 1) == 0 && driver->inhibitCallback)
             driver->inhibitCallback(true, driver->inhibitOpaque);
 
         /* Run an early hook to set-up missing devices */
@@ -8146,7 +8146,7 @@ qemuProcessReconnect(void *opaque)
             goto error;
     }
 
-    if (virAtomicIntInc(&driver->nactive) == 0 && driver->inhibitCallback)
+    if (g_atomic_int_add(&driver->nactive, 1) == 0 && driver->inhibitCallback)
         driver->inhibitCallback(true, driver->inhibitOpaque);
 
  cleanup:
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 4e159157d7..ba157c0686 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -695,7 +695,7 @@ testDomainStartState(testDriverPtr privconn,
     int ret = -1;
 
     virDomainObjSetState(dom, VIR_DOMAIN_RUNNING, reason);
-    dom->def->id = virAtomicIntInc(&privconn->nextDomID);
+    dom->def->id = g_atomic_int_add(&privconn->nextDomID, 1);
 
     if (virDomainObjSetDefTransient(privconn->xmlopt,
                                     dom, NULL) < 0) {
diff --git a/src/util/viratomic.h b/src/util/viratomic.h
index 2811447a29..152cfcd903 100644
--- a/src/util/viratomic.h
+++ b/src/util/viratomic.h
@@ -26,17 +26,6 @@
 
 #include "internal.h"
 
-/**
- * virAtomicIntInc:
- * Increments the value of atomic by 1.
- *
- * Think of this operation as an atomic version of
- * { tmp = *atomic; *atomic += 1; return tmp; }
- *
- * This call acts as a full compiler and hardware memory barrier.
- */
-#define virAtomicIntInc(i) g_atomic_int_add(i, 1)
-
 /**
  * virAtomicIntDecAndTest:
  * Decrements the value of atomic by 1.
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 8cece6e735..9185d3e92e 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -182,7 +182,7 @@ virClassNew(virClassPtr parent,
         goto error;
 
     klass->parent = parent;
-    klass->magic = virAtomicIntInc(&magicCounter);
+    klass->magic = g_atomic_int_add(&magicCounter, 1);
     if (klass->magic > 0xCAFEFFFF) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("too many object classes defined"));
@@ -382,7 +382,7 @@ virObjectRef(void *anyobj)
 
     if (VIR_OBJECT_NOTVALID(obj))
         return NULL;
-    virAtomicIntInc(&obj->u.s.refs);
+    g_atomic_int_add(&obj->u.s.refs, 1);
     PROBE(OBJECT_REF, "obj=%p", obj);
     return anyobj;
 }
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 60419538e2..689db4f19d 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -1048,7 +1048,7 @@ int virProcessGetStartTime(pid_t pid,
                            unsigned long long *timestamp)
 {
     static int warned;
-    if (virAtomicIntInc(&warned) == 0) {
+    if (g_atomic_int_add(&warned, 1) == 0) {
         VIR_WARN("Process start time of pid %lld not available on this platform",
                  (long long) pid);
     }
-- 
2.24.1





[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