src: Replace virAtomicIntInc() with g_atomic_int_add()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2020-01-31 17:04:24 +01:00
parent f127acfa34
commit 574678a27f
8 changed files with 14 additions and 25 deletions

View File

@ -1471,7 +1471,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver,
if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0) if (virDomainObjSave(vm, driver->xmlopt, cfg->stateDir) < 0)
goto destroy_dom; 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); driver->inhibitCallback(true, driver->inhibitOpaque);
/* finally we can call the 'started' hook script if any */ /* finally we can call the 'started' hook script if any */

View File

@ -446,7 +446,7 @@ libxlReconnectDomain(virDomainObjPtr vm,
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
VIR_DOMAIN_RUNNING_UNKNOWN); 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); driver->inhibitCallback(true, driver->inhibitOpaque);
/* Enable domain death events */ /* Enable domain death events */

View File

@ -1468,7 +1468,7 @@ int virLXCProcessStart(virConnectPtr conn,
if (virCommandHandshakeNotify(cmd) < 0) if (virCommandHandshakeNotify(cmd) < 0)
goto cleanup; 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); driver->inhibitCallback(true, driver->inhibitOpaque);
if (lxcContainerWaitForContinue(handshakefds[0]) < 0) { if (lxcContainerWaitForContinue(handshakefds[0]) < 0) {
@ -1670,7 +1670,7 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
VIR_DOMAIN_RUNNING_UNKNOWN); 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); driver->inhibitCallback(true, driver->inhibitOpaque);
if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm))) if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))

View File

@ -541,7 +541,7 @@ virNWFilterSnoopReqLeaseTimerRun(virNWFilterSnoopReqPtr req)
static void static void
virNWFilterSnoopReqGet(virNWFilterSnoopReqPtr req) 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 */ /* put the lease on the req's list */
virNWFilterSnoopIPLeaseTimerAdd(pl); virNWFilterSnoopIPLeaseTimerAdd(pl);
virAtomicIntInc(&virNWFilterSnoopState.nLeases); g_atomic_int_add(&virNWFilterSnoopState.nLeases, 1);
exit: exit:
if (update_leasefile) if (update_leasefile)
@ -1172,7 +1172,7 @@ virNWFilterSnoopDHCPDecodeJobSubmit(virThreadPoolPtr pool,
ret = virThreadPoolSendJob(pool, 0, job); ret = virThreadPoolSendJob(pool, 0, job);
if (ret == 0) if (ret == 0)
virAtomicIntInc(qCtr); g_atomic_int_add(qCtr, 1);
else else
VIR_FREE(job); VIR_FREE(job);
@ -1649,7 +1649,7 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
threadPuts = true; threadPuts = true;
virAtomicIntInc(&virNWFilterSnoopState.nThreads); g_atomic_int_add(&virNWFilterSnoopState.nThreads, 1);
req->threadkey = virNWFilterSnoopActivate(req); req->threadkey = virNWFilterSnoopActivate(req);
if (!req->threadkey) { if (!req->threadkey) {
@ -1777,7 +1777,7 @@ virNWFilterSnoopLeaseFileSave(virNWFilterSnoopIPLeasePtr ipl)
goto err_exit; goto err_exit;
/* keep dead leases at < ~95% of file size */ /* 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) g_atomic_int_get(&virNWFilterSnoopState.nLeases) * 20)
virNWFilterSnoopLeaseFileLoad(); /* load & refresh lease file */ virNWFilterSnoopLeaseFileLoad(); /* load & refresh lease file */

View File

@ -5571,7 +5571,7 @@ qemuProcessInit(virQEMUDriverPtr driver,
qemuDomainSetFakeReboot(driver, vm, false); qemuDomainSetFakeReboot(driver, vm, false);
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_STARTING_UP); 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); driver->inhibitCallback(true, driver->inhibitOpaque);
/* Run an early hook to set-up missing devices */ /* Run an early hook to set-up missing devices */
@ -8146,7 +8146,7 @@ qemuProcessReconnect(void *opaque)
goto error; 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); driver->inhibitCallback(true, driver->inhibitOpaque);
cleanup: cleanup:

View File

@ -26,17 +26,6 @@
#include "internal.h" #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: * virAtomicIntDecAndTest:
* Decrements the value of atomic by 1. * Decrements the value of atomic by 1.

View File

@ -182,7 +182,7 @@ virClassNew(virClassPtr parent,
goto error; goto error;
klass->parent = parent; klass->parent = parent;
klass->magic = virAtomicIntInc(&magicCounter); klass->magic = g_atomic_int_add(&magicCounter, 1);
if (klass->magic > 0xCAFEFFFF) { if (klass->magic > 0xCAFEFFFF) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("too many object classes defined")); _("too many object classes defined"));
@ -382,7 +382,7 @@ virObjectRef(void *anyobj)
if (VIR_OBJECT_NOTVALID(obj)) if (VIR_OBJECT_NOTVALID(obj))
return NULL; return NULL;
virAtomicIntInc(&obj->u.s.refs); g_atomic_int_add(&obj->u.s.refs, 1);
PROBE(OBJECT_REF, "obj=%p", obj); PROBE(OBJECT_REF, "obj=%p", obj);
return anyobj; return anyobj;
} }

View File

@ -1048,7 +1048,7 @@ int virProcessGetStartTime(pid_t pid,
unsigned long long *timestamp) unsigned long long *timestamp)
{ {
static int warned; 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", VIR_WARN("Process start time of pid %lld not available on this platform",
(long long) pid); (long long) pid);
} }