[PATCH 0/7] Drop virAtomic module

Inspired by: https://www.redhat.com/archives/libvir-list/2020-January/msg01446.html Instead of using: #define virAtomicIntXXX g_atomic_int_XXX let's use the GLib directly and drop needless defines. Michal Prívozník (7): test_driver: Replace virAtomicIntAdd() with virAtomicIntInc() tests: Drop viratomictest src: Replace virAtomicIntGet() with g_atomic_int_get() src: Replace virAtomicIntSet() with g_atomic_int_set() src: Replace virAtomicIntInc() with g_atomic_int_add() src: Drop virAtomicIntDecAndTest() with g_atomic_int_dec_and_test() Drop virAtomic module configure.ac | 1 - m4/virt-atomic.m4 | 77 ------------- src/Makefile.am | 6 - src/libvirt_atomic.syms | 11 -- src/libxl/libxl_domain.c | 5 +- src/libxl/libxl_driver.c | 3 +- src/lxc/lxc_process.c | 7 +- src/nwfilter/nwfilter_dhcpsnoop.c | 33 +++--- src/qemu/qemu_conf.c | 1 - src/qemu/qemu_domain.c | 1 - src/qemu/qemu_process.c | 7 +- src/test/test_driver.c | 7 +- src/util/Makefile.inc.am | 2 - src/util/viratomic.c | 35 ------ src/util/viratomic.h | 130 ---------------------- src/util/virobject.c | 9 +- src/util/virprocess.c | 3 +- src/util/virsystemd.c | 17 ++- tests/Makefile.am | 5 - tests/viratomictest.c | 175 ------------------------------ 20 files changed, 41 insertions(+), 494 deletions(-) delete mode 100644 m4/virt-atomic.m4 delete mode 100644 src/libvirt_atomic.syms delete mode 100644 src/util/viratomic.c delete mode 100644 src/util/viratomic.h delete mode 100644 tests/viratomictest.c -- 2.24.1

Instead of calling virAtomicIntAdd(&var, 1); we can call virAtomicIntInc(&var) directly. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/test/test_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 47c1fc588f..6f617592f3 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 = virAtomicIntAdd(&privconn->nextDomID, 1); + dom->def->id = virAtomicIntInc(&privconn->nextDomID); if (virDomainObjSetDefTransient(privconn->xmlopt, dom, NULL) < 0) { -- 2.24.1

On Sat, Feb 01, 2020 at 07:33:43AM +0100, Michal Privoznik wrote:
Instead of calling virAtomicIntAdd(&var, 1); we can call virAtomicIntInc(&var) directly.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/test/test_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 47c1fc588f..6f617592f3 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 = virAtomicIntAdd(&privconn->nextDomID, 1); + dom->def->id = virAtomicIntInc(&privconn->nextDomID);
g_atomic_int_add(&privconn->nextDomID, 1); I don't see the value of changing it to a function that is being phased out. With that fixed: Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

In future commits our virAtomic* APIs will be replaced with their GLib variants. Instead of trying to update the test after each commit and eventually removing the test anyway, remove it upfront and save the hassle. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/Makefile.am | 5 -- tests/viratomictest.c | 175 ------------------------------------------ 2 files changed, 180 deletions(-) delete mode 100644 tests/viratomictest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 19705c6b76..ef49b122cd 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -179,7 +179,6 @@ test_programs = virshtest sockettest \ virhostcputest virbuftest \ commandtest seclabeltest \ virhashtest virconftest \ - viratomictest \ utiltest shunloadtest \ virtimetest viruritest virkeyfiletest \ viralloctest \ @@ -1456,10 +1455,6 @@ virhashtest_SOURCES = \ virhashtest.c virhashdata.h testutils.h testutils.c virhashtest_LDADD = $(LDADDS) -viratomictest_SOURCES = \ - viratomictest.c testutils.h testutils.c -viratomictest_LDADD = $(LDADDS) - virbitmaptest_SOURCES = \ virbitmaptest.c testutils.h testutils.c virbitmaptest_LDADD = $(LDADDS) diff --git a/tests/viratomictest.c b/tests/viratomictest.c deleted file mode 100644 index e30df66cd7..0000000000 --- a/tests/viratomictest.c +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (C) 2011-2013 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see - * <http://www.gnu.org/licenses/>. - * - */ - -#include <config.h> - -#include <time.h> -#include <sched.h> - -#include "testutils.h" - -#include "viratomic.h" -#include "virrandom.h" -#include "virthread.h" - -static int -testTypes(const void *data G_GNUC_UNUSED) -{ - unsigned int u, u2; - int s, s2; - bool res; - -#define testAssertEq(a, b) \ - if (!(a == b)) \ - return -1; - virAtomicIntSet(&u, 5); - u2 = virAtomicIntGet(&u); - testAssertEq(u2, 5); - - res = virAtomicIntCompareExchange(&u, 6, 7); - if (res) - return -1; - testAssertEq(u, 5); - - testAssertEq(virAtomicIntAdd(&u, 1), 5); - testAssertEq(u, 6); - - testAssertEq(virAtomicIntInc(&u), 6); - testAssertEq(u, 7); - - res = virAtomicIntDecAndTest(&u); - if (res) - return -1; - testAssertEq(u, 6); - - u2 = virAtomicIntAnd(&u, 5); - testAssertEq(u2, 6); - testAssertEq(u, 4); - - u2 = virAtomicIntOr(&u, 8); - testAssertEq(u2, 4); - testAssertEq(u, 12); - - u2 = virAtomicIntXor(&u, 4); - testAssertEq(u2, 12); - testAssertEq(u, 8); - - virAtomicIntSet(&s, 5); - s2 = virAtomicIntGet(&s); - testAssertEq(s2, 5); - - res = virAtomicIntCompareExchange(&s, 6, 7); - if (res) - return -1; - testAssertEq(s, 5); - - virAtomicIntAdd(&s, 1); - testAssertEq(s, 6); - - virAtomicIntInc(&s); - testAssertEq(s, 7); - - res = virAtomicIntDecAndTest(&s); - if (res) - return -1; - testAssertEq(s, 6); - - s2 = virAtomicIntAnd(&s, 5); - testAssertEq(s2, 6); - testAssertEq(s, 4); - - s2 = virAtomicIntOr(&s, 8); - testAssertEq(s2, 4); - testAssertEq(s, 12); - - s2 = virAtomicIntXor(&s, 4); - testAssertEq(s2, 12); - testAssertEq(s, 8); - - return 0; -} - -#define THREADS 10 -#define ROUNDS 10000 - -volatile int bucket[THREADS]; -volatile int atomic; - -static void -thread_func(void *data) -{ - int idx = (intptr_t)data; - size_t i; - int d; - - for (i = 0; i < ROUNDS; i++) { - d = virRandomBits(7); - bucket[idx] += d; - virAtomicIntAdd(&atomic, d); -#ifdef WIN32 - SleepEx(0, 0); -#else - sched_yield(); -#endif - } -} - -static int -testThreads(const void *data G_GNUC_UNUSED) -{ - int sum; - size_t i; - virThread threads[THREADS]; - - atomic = 0; - for (i = 0; i < THREADS; i++) - bucket[i] = 0; - - for (i = 0; i < THREADS; i++) { - if (virThreadCreate(&(threads[i]), true, thread_func, (void*)(intptr_t)i) < 0) - return -1; - } - - for (i = 0; i < THREADS; i++) - virThreadJoin(&threads[i]); - - sum = 0; - for (i = 0; i < THREADS; i++) - sum += bucket[i]; - - if (sum != atomic) - return -1; - - return 0; -} - -static int -mymain(void) -{ - int ret = 0; - - if (virTestRun("types", testTypes, NULL) < 0) - ret = -1; - if (virTestRun("threads", testThreads, NULL) < 0) - ret = -1; - - return ret; -} - -VIR_TEST_MAIN(mymain) -- 2.24.1

On Sat, Feb 01, 2020 at 07:33:44AM +0100, Michal Privoznik wrote:
In future commits our virAtomic* APIs will be replaced with their GLib variants. Instead of trying to update the test after each commit and eventually removing the test anyway, remove it upfront and save the hassle.
Alternatively, you could have just removed their usage, not the APIs themselves.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/Makefile.am | 5 -- tests/viratomictest.c | 175 ------------------------------------------ 2 files changed, 180 deletions(-) delete mode 100644 tests/viratomictest.c
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/nwfilter/nwfilter_dhcpsnoop.c | 12 ++++++------ src/util/viratomic.h | 9 --------- src/util/virsystemd.c | 6 +++--- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index a1c0c0189e..074cffecb2 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -601,7 +601,7 @@ virNWFilterSnoopReqFree(virNWFilterSnoopReqPtr req) if (!req) return; - if (virAtomicIntGet(&req->refctr) != 0) + if (g_atomic_int_get(&req->refctr) != 0) return; /* free all leases */ @@ -1477,7 +1477,7 @@ virNWFilterDHCPSnoopThread(void *req0) unsigned int diff; /* submit packet to worker thread */ - if (virAtomicIntGet(&pcapConf[i].qCtr) > + if (g_atomic_int_get(&pcapConf[i].qCtr) > pcapConf[i].maxQSize) { if (last_displayed_queue - time(0) > 10) { last_displayed_queue = time(0); @@ -1778,7 +1778,7 @@ virNWFilterSnoopLeaseFileSave(virNWFilterSnoopIPLeasePtr ipl) /* keep dead leases at < ~95% of file size */ if (virAtomicIntInc(&virNWFilterSnoopState.wLeases) >= - virAtomicIntGet(&virNWFilterSnoopState.nLeases) * 20) + g_atomic_int_get(&virNWFilterSnoopState.nLeases) * 20) virNWFilterSnoopLeaseFileLoad(); /* load & refresh lease file */ err_exit: @@ -1809,7 +1809,7 @@ virNWFilterSnoopPruneIter(const void *payload, /* * have the entry removed if it has no leases and no one holds a ref */ - del_req = ((req->start == NULL) && (virAtomicIntGet(&req->refctr) == 0)); + del_req = ((req->start == NULL) && (g_atomic_int_get(&req->refctr) == 0)); virNWFilterSnoopReqUnlock(req); @@ -1973,9 +1973,9 @@ virNWFilterSnoopLeaseFileLoad(void) static void virNWFilterSnoopJoinThreads(void) { - while (virAtomicIntGet(&virNWFilterSnoopState.nThreads) != 0) { + while (g_atomic_int_get(&virNWFilterSnoopState.nThreads) != 0) { VIR_WARN("Waiting for snooping threads to terminate: %u", - virAtomicIntGet(&virNWFilterSnoopState.nThreads)); + g_atomic_int_get(&virNWFilterSnoopState.nThreads)); g_usleep(1000 * 1000); } } diff --git a/src/util/viratomic.h b/src/util/viratomic.h index 12b116a6cd..6c1764f7bf 100644 --- a/src/util/viratomic.h +++ b/src/util/viratomic.h @@ -26,15 +26,6 @@ #include "internal.h" -/** - * virAtomicIntGet: - * Gets the current value of atomic. - * - * This call acts as a full compiler and hardware memory barrier - * (before the get) - */ -#define virAtomicIntGet(v) g_atomic_int_get(v) - /** * virAtomicIntSet: * Sets the value of atomic to newval. diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index a9ff782fb8..5b66094de5 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -154,7 +154,7 @@ virSystemdHasMachined(void) int ret; int val; - val = virAtomicIntGet(&virSystemdHasMachinedCachedValue); + val = g_atomic_int_get(&virSystemdHasMachinedCachedValue); if (val != -1) return val; @@ -176,7 +176,7 @@ virSystemdHasLogind(void) int ret; int val; - val = virAtomicIntGet(&virSystemdHasLogindCachedValue); + val = g_atomic_int_get(&virSystemdHasLogindCachedValue); if (val != -1) return val; @@ -352,7 +352,7 @@ int virSystemdCreateMachine(const char *name, */ VIR_DEBUG("Attempting to create machine via systemd"); - if (virAtomicIntGet(&hasCreateWithNetwork)) { + if (g_atomic_int_get(&hasCreateWithNetwork)) { virError error; memset(&error, 0, sizeof(error)); -- 2.24.1

On Sat, Feb 01, 2020 at 07:33:45AM +0100, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/nwfilter/nwfilter_dhcpsnoop.c | 12 ++++++------ src/util/viratomic.h | 9 --------- src/util/virsystemd.c | 6 +++--- 3 files changed, 9 insertions(+), 18 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/nwfilter/nwfilter_dhcpsnoop.c | 2 +- src/test/test_driver.c | 4 ++-- src/util/viratomic.h | 9 --------- src/util/virobject.c | 2 +- src/util/virsystemd.c | 10 +++++----- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index 074cffecb2..b82779609d 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -1884,7 +1884,7 @@ virNWFilterSnoopLeaseFileRefresh(void) TMPLEASEFILE, LEASEFILE); unlink(TMPLEASEFILE); } - virAtomicIntSet(&virNWFilterSnoopState.wLeases, 0); + g_atomic_int_set(&virNWFilterSnoopState.wLeases, 0); skip_rename: virNWFilterSnoopLeaseFileOpen(); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6f617592f3..4e159157d7 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -106,7 +106,7 @@ struct _testDriver { size_t numAuths; testAuthPtr auths; - /* virAtomic access only */ + /* g_atomic access only */ volatile int nextDomID; /* immutable pointer, immutable object after being initialized with @@ -448,7 +448,7 @@ testDriverNew(void) !(ret->pools = virStoragePoolObjListNew())) goto error; - virAtomicIntSet(&ret->nextDomID, 1); + g_atomic_int_set(&ret->nextDomID, 1); return ret; diff --git a/src/util/viratomic.h b/src/util/viratomic.h index 6c1764f7bf..2811447a29 100644 --- a/src/util/viratomic.h +++ b/src/util/viratomic.h @@ -26,15 +26,6 @@ #include "internal.h" -/** - * virAtomicIntSet: - * Sets the value of atomic to newval. - * - * This call acts as a full compiler and hardware memory barrier - * (after the set) - */ -#define virAtomicIntSet(i, newv) g_atomic_int_set(i, newv) - /** * virAtomicIntInc: * Increments the value of atomic by 1. diff --git a/src/util/virobject.c b/src/util/virobject.c index 5af14234f2..8cece6e735 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -246,7 +246,7 @@ virObjectNew(virClassPtr klass) obj->u.s.magic = klass->magic; obj->klass = klass; - virAtomicIntSet(&obj->u.s.refs, 1); + g_atomic_int_set(&obj->u.s.refs, 1); PROBE(OBJECT_NEW, "obj=%p classname=%s", obj, obj->klass->name); diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 5b66094de5..6b47f4fa36 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -160,13 +160,13 @@ virSystemdHasMachined(void) if ((ret = virDBusIsServiceEnabled("org.freedesktop.machine1")) < 0) { if (ret == -2) - virAtomicIntSet(&virSystemdHasMachinedCachedValue, -2); + g_atomic_int_set(&virSystemdHasMachinedCachedValue, -2); return ret; } if ((ret = virDBusIsServiceRegistered("org.freedesktop.systemd1")) == -1) return ret; - virAtomicIntSet(&virSystemdHasMachinedCachedValue, ret); + g_atomic_int_set(&virSystemdHasMachinedCachedValue, ret); return ret; } @@ -183,14 +183,14 @@ virSystemdHasLogind(void) ret = virDBusIsServiceEnabled("org.freedesktop.login1"); if (ret < 0) { if (ret == -2) - virAtomicIntSet(&virSystemdHasLogindCachedValue, -2); + g_atomic_int_set(&virSystemdHasLogindCachedValue, -2); return ret; } if ((ret = virDBusIsServiceRegistered("org.freedesktop.login1")) == -1) return ret; - virAtomicIntSet(&virSystemdHasLogindCachedValue, ret); + g_atomic_int_set(&virSystemdHasLogindCachedValue, ret); return ret; } @@ -386,7 +386,7 @@ int virSystemdCreateMachine(const char *name, VIR_INFO("CreateMachineWithNetwork isn't supported, switching " "to legacy CreateMachine method for systemd-machined"); virResetError(&error); - virAtomicIntSet(&hasCreateWithNetwork, 0); + g_atomic_int_set(&hasCreateWithNetwork, 0); /* Could re-structure without Using goto, but this * avoids another atomic read which would trigger * another memory barrier */ -- 2.24.1

On Sat, Feb 01, 2020 at 07:33:46AM +0100, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/nwfilter/nwfilter_dhcpsnoop.c | 2 +- src/test/test_driver.c | 4 ++-- src/util/viratomic.h | 9 --------- src/util/virobject.c | 2 +- src/util/virsystemd.c | 10 +++++----- 5 files changed, 9 insertions(+), 18 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- 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

On Sat, Feb 01, 2020 at 07:33:47AM +0100, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- 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/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) {
This belongs in patch 1/7 To the rest: Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libxl/libxl_domain.c | 2 +- src/lxc/lxc_process.c | 2 +- src/nwfilter/nwfilter_dhcpsnoop.c | 8 ++++---- src/qemu/qemu_process.c | 2 +- src/util/viratomic.h | 11 ----------- src/util/virobject.c | 2 +- 6 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index 8885af451f..d53363dc02 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -878,7 +878,7 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver, priv->ignoreDeathEvent = false; - if (virAtomicIntDecAndTest(&driver->nactive) && driver->inhibitCallback) + if (!!g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCallback) driver->inhibitCallback(false, driver->inhibitOpaque); if ((vm->def->ngraphics == 1) && diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 2bb2216dc0..d8ddea6d24 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -208,7 +208,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, vm->pid = -1; vm->def->id = -1; - if (virAtomicIntDecAndTest(&driver->nactive) && driver->inhibitCallback) + if (!!g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCallback) driver->inhibitCallback(false, driver->inhibitOpaque); virLXCDomainReAttachHostDevices(driver, vm->def); diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index f73913ec9e..c4341ee3e2 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -692,7 +692,7 @@ virNWFilterSnoopReqPut(virNWFilterSnoopReqPtr req) virNWFilterSnoopLock(); - if (virAtomicIntDecAndTest(&req->refctr)) { + if (!!g_atomic_int_dec_and_test(&req->refctr)) { /* * delete the request: * - if we don't find req on the global list anymore @@ -868,7 +868,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req, skip_instantiate: VIR_FREE(ipl); - ignore_value(virAtomicIntDecAndTest(&virNWFilterSnoopState.nLeases)); + ignore_value(!!g_atomic_int_dec_and_test(&virNWFilterSnoopState.nLeases)); lease_not_found: VIR_FREE(ipstr); @@ -1142,7 +1142,7 @@ static void virNWFilterDHCPDecodeWorker(void *jobdata, void *opaque) _("Instantiation of rules failed on " "interface '%s'"), req->binding->portdevname); } - ignore_value(virAtomicIntDecAndTest(job->qCtr)); + ignore_value(!!g_atomic_int_dec_and_test(job->qCtr)); VIR_FREE(job); } @@ -1543,7 +1543,7 @@ virNWFilterDHCPSnoopThread(void *req0) pcap_close(pcapConf[i].handle); } - ignore_value(virAtomicIntDecAndTest(&virNWFilterSnoopState.nThreads)); + ignore_value(!!g_atomic_int_dec_and_test(&virNWFilterSnoopState.nThreads)); return; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 20c4e3bb5d..ed14ce5ea2 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7313,7 +7313,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, qemuProcessBuildDestroyMemoryPaths(driver, vm, NULL, false); - if (virAtomicIntDecAndTest(&driver->nactive) && driver->inhibitCallback) + if (!!g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCallback) driver->inhibitCallback(false, driver->inhibitOpaque); /* Wake up anything waiting on domain condition */ diff --git a/src/util/viratomic.h b/src/util/viratomic.h index 152cfcd903..1ddc7019f9 100644 --- a/src/util/viratomic.h +++ b/src/util/viratomic.h @@ -26,17 +26,6 @@ #include "internal.h" -/** - * virAtomicIntDecAndTest: - * Decrements the value of atomic by 1. - * - * Think of this operation as an atomic version of - * { *atomic -= 1; return *atomic == 0; } - * - * This call acts as a full compiler and hardware memory barrier. - */ -#define virAtomicIntDecAndTest(i) (!!g_atomic_int_dec_and_test(i)) - /** * virAtomicIntCompareExchange: * Compares atomic to oldval and, if equal, sets it to newval. If diff --git a/src/util/virobject.c b/src/util/virobject.c index 9185d3e92e..7749d89243 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -344,7 +344,7 @@ virObjectUnref(void *anyobj) if (VIR_OBJECT_NOTVALID(obj)) return false; - bool lastRef = virAtomicIntDecAndTest(&obj->u.s.refs); + bool lastRef = !!g_atomic_int_dec_and_test(&obj->u.s.refs); PROBE(OBJECT_UNREF, "obj=%p", obj); if (lastRef) { PROBE(OBJECT_DISPOSE, "obj=%p", obj); -- 2.24.1

On Sat, Feb 01, 2020 at 07:33:48AM +0100, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libxl/libxl_domain.c | 2 +- src/lxc/lxc_process.c | 2 +- src/nwfilter/nwfilter_dhcpsnoop.c | 8 ++++---- src/qemu/qemu_process.c | 2 +- src/util/viratomic.h | 11 ----------- src/util/virobject.c | 2 +- 6 files changed, 8 insertions(+), 19 deletions(-)
@@ -868,7 +868,7 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req, skip_instantiate: VIR_FREE(ipl);
- ignore_value(virAtomicIntDecAndTest(&virNWFilterSnoopState.nLeases)); + ignore_value(!!g_atomic_int_dec_and_test(&virNWFilterSnoopState.nLeases));
lease_not_found: VIR_FREE(ipstr); @@ -1142,7 +1142,7 @@ static void virNWFilterDHCPDecodeWorker(void *jobdata, void *opaque) _("Instantiation of rules failed on " "interface '%s'"), req->binding->portdevname); } - ignore_value(virAtomicIntDecAndTest(job->qCtr)); + ignore_value(!!g_atomic_int_dec_and_test(job->qCtr)); VIR_FREE(job); }
@@ -1543,7 +1543,7 @@ virNWFilterDHCPSnoopThread(void *req0) pcap_close(pcapConf[i].handle); }
- ignore_value(virAtomicIntDecAndTest(&virNWFilterSnoopState.nThreads)); + ignore_value(!!g_atomic_int_dec_and_test(&virNWFilterSnoopState.nThreads));
return; }
Here you can drop the ignore_value as well as the !! double inversion. Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Now, that every use of virAtomic was replaced with its g_atomic equivalent, let's remove the module. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- configure.ac | 1 - m4/virt-atomic.m4 | 77 -------------------------- src/Makefile.am | 6 --- src/libvirt_atomic.syms | 11 ---- src/libxl/libxl_domain.c | 1 - src/libxl/libxl_driver.c | 1 - src/lxc/lxc_process.c | 1 - src/nwfilter/nwfilter_dhcpsnoop.c | 1 - src/qemu/qemu_conf.c | 1 - src/qemu/qemu_domain.c | 1 - src/qemu/qemu_process.c | 1 - src/test/test_driver.c | 1 - src/util/Makefile.inc.am | 2 - src/util/viratomic.c | 35 ------------ src/util/viratomic.h | 90 ------------------------------- src/util/virobject.c | 1 - src/util/virprocess.c | 1 - src/util/virsystemd.c | 1 - 18 files changed, 233 deletions(-) delete mode 100644 m4/virt-atomic.m4 delete mode 100644 src/libvirt_atomic.syms delete mode 100644 src/util/viratomic.c delete mode 100644 src/util/viratomic.h diff --git a/configure.ac b/configure.ac index b1f75fa751..5bd9bc841a 100644 --- a/configure.ac +++ b/configure.ac @@ -302,7 +302,6 @@ LIBVIRT_ARG_YAJL LIBVIRT_CHECK_ACL LIBVIRT_CHECK_APPARMOR -LIBVIRT_CHECK_ATOMIC LIBVIRT_CHECK_ATTR LIBVIRT_CHECK_AUDIT LIBVIRT_CHECK_BASH_COMPLETION diff --git a/m4/virt-atomic.m4 b/m4/virt-atomic.m4 deleted file mode 100644 index d96f7a2bac..0000000000 --- a/m4/virt-atomic.m4 +++ /dev/null @@ -1,77 +0,0 @@ -dnl The atomic implementation check -dnl -dnl Copyright (C) 2016 Red Hat, Inc. -dnl -dnl This library is free software; you can redistribute it and/or -dnl modify it under the terms of the GNU Lesser General Public -dnl License as published by the Free Software Foundation; either -dnl version 2.1 of the License, or (at your option) any later version. -dnl -dnl This library is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -dnl Lesser General Public License for more details. -dnl -dnl You should have received a copy of the GNU Lesser General Public -dnl License along with this library. If not, see -dnl <http://www.gnu.org/licenses/>. -dnl - -AC_DEFUN([LIBVIRT_CHECK_ATOMIC], [ - AC_REQUIRE([LIBVIRT_CHECK_PTHREAD]) - - dnl We need to decide at configure time if libvirt will use real atomic - dnl operations ("lock free") or emulated ones with a mutex. - dnl - dnl Note that the atomic ops are only available with GCC on x86 when - dnl using -march=i486 or higher. If we detect that the atomic ops are - dnl not available but would be available given the right flags, we want - dnl to abort and advise the user to fix their CFLAGS. It's better to do - dnl that then to silently fall back on emulated atomic ops just because - dnl the user had the wrong build environment. - - atomic_ops= - - AC_MSG_CHECKING([for atomic ops implementation]) - - AC_TRY_COMPILE([], [__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;],[ - atomic_ops=gcc - ],[]) - - if test "$atomic_ops" = "" ; then - SAVE_CFLAGS="${CFLAGS}" - CFLAGS="-march=i486" - AC_TRY_COMPILE([], - [__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;], - [AC_MSG_ERROR([Libvirt must be built with -march=i486 or later.])], - []) - CFLAGS="${SAVE_CFLAGS}" - - case "$host" in - *-*-mingw* | *-*-msvc* ) - atomic_ops=win32 - ;; - *) - if test "$ac_cv_header_pthread_h" = "yes" ; then - atomic_ops=pthread - else - AC_MSG_ERROR([Libvirt must be built with GCC or have pthread.h on non-Win32 platforms]) - fi - ;; - esac - fi - - case "$atomic_ops" in - gcc) - AC_DEFINE([VIR_ATOMIC_OPS_GCC],[1],[Use GCC atomic ops]) - ;; - win32) - AC_DEFINE([VIR_ATOMIC_OPS_WIN32],[1],[Use Win32 atomic ops]) - ;; - pthread) - AC_DEFINE([VIR_ATOMIC_OPS_PTHREAD],[1],[Use pthread atomic ops emulation]) - ;; - esac - AM_CONDITIONAL([WITH_ATOMIC_OPS_PTHREAD],[test "$atomic_ops" = "pthread"]) - AC_MSG_RESULT([$atomic_ops]) -]) diff --git a/src/Makefile.am b/src/Makefile.am index 58355c5337..7bb6127ca4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -390,12 +390,6 @@ else ! WITH_SSH2 SYM_FILES += $(srcdir)/libvirt_libssh2.syms endif ! WITH_SSH2 -if WITH_ATOMIC_OPS_PTHREAD -USED_SYM_FILES += $(srcdir)/libvirt_atomic.syms -else ! WITH_ATOMIC_OPS_PTHREAD -SYM_FILES += $(srcdir)/libvirt_atomic.syms -endif ! WITH_ATOMIC_OPS_PTHREAD - if WITH_LIBSSH USED_SYM_FILES += $(srcdir)/libvirt_libssh.syms else ! WITH_LIBSSH diff --git a/src/libvirt_atomic.syms b/src/libvirt_atomic.syms deleted file mode 100644 index e2c23637d1..0000000000 --- a/src/libvirt_atomic.syms +++ /dev/null @@ -1,11 +0,0 @@ -# -# These symbols are dependent upon !VIR_ATOMIC_OPS_GCC. -# - -# util/viratomic.h -virAtomicLock; - -# Let emacs know we want case-insensitive sorting -# Local Variables: -# sort-fold-case: t -# End: diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index d53363dc02..c8b68665af 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -26,7 +26,6 @@ #include "libxl_capabilities.h" #include "viralloc.h" -#include "viratomic.h" #include "virfile.h" #include "virerror.h" #include "virhook.h" diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 41cbb67e3a..2b06f1be1e 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -50,7 +50,6 @@ #include "virstring.h" #include "virsysinfo.h" #include "viraccessapicheck.h" -#include "viratomic.h" #include "virhostdev.h" #include "virpidfile.h" #include "locking/domain_lock.h" diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index d8ddea6d24..da2541e684 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -48,7 +48,6 @@ #include "lxc_hostdev.h" #include "virhook.h" #include "virstring.h" -#include "viratomic.h" #include "virprocess.h" #include "virsystemd.h" #include "netdev_bandwidth_conf.h" diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index c4341ee3e2..e7f5b511ae 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -55,7 +55,6 @@ #include "nwfilter_ipaddrmap.h" #include "virnetdev.h" #include "virfile.h" -#include "viratomic.h" #include "virsocketaddr.h" #include "virthreadpool.h" #include "configmake.h" diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 0b119cbe78..024f3c1634 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -45,7 +45,6 @@ #include "virfile.h" #include "virsocket.h" #include "virstring.h" -#include "viratomic.h" #include "storage_conf.h" #include "configmake.h" diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d3045b4bcd..cb691ca048 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -51,7 +51,6 @@ #include "virstoragefile.h" #include "virstring.h" #include "virthreadjob.h" -#include "viratomic.h" #include "virprocess.h" #include "vircrypto.h" #include "virrandom.h" diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index ed14ce5ea2..ddcc763cfd 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -79,7 +79,6 @@ #include "virnetdevopenvswitch.h" #include "virnetdevmidonet.h" #include "virbitmap.h" -#include "viratomic.h" #include "virnuma.h" #include "virstring.h" #include "virhostdev.h" diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ba157c0686..6a629988ef 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -59,7 +59,6 @@ #include "virstring.h" #include "cpu/cpu.h" #include "virauth.h" -#include "viratomic.h" #include "virdomainobjlist.h" #include "virinterfaceobj.h" #include "virhostcpu.h" diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am index 528c9f6cfe..2abdca548c 100644 --- a/src/util/Makefile.inc.am +++ b/src/util/Makefile.inc.am @@ -11,8 +11,6 @@ UTIL_SOURCES = \ util/virarch.h \ util/virarptable.c \ util/virarptable.h \ - util/viratomic.c \ - util/viratomic.h \ util/viraudit.c \ util/viraudit.h \ util/virauth.c \ diff --git a/src/util/viratomic.c b/src/util/viratomic.c deleted file mode 100644 index 278a749b6e..0000000000 --- a/src/util/viratomic.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * viratomic.c: atomic integer operations - * - * Copyright (C) 2012 Red Hat, Inc. - * - * Based on code taken from GLib 2.32, under the LGPLv2+ - * - * Copyright (C) 2011 Ryan Lortie - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see - * <http://www.gnu.org/licenses/>. - * - */ - -#include <config.h> - -#include "viratomic.h" - - -#ifdef VIR_ATOMIC_OPS_PTHREAD - -pthread_mutex_t virAtomicLock = PTHREAD_MUTEX_INITIALIZER; - -#endif diff --git a/src/util/viratomic.h b/src/util/viratomic.h deleted file mode 100644 index 1ddc7019f9..0000000000 --- a/src/util/viratomic.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * viratomic.h: atomic integer operations - * - * Copyright (C) 2012-2020 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see - * <http://www.gnu.org/licenses/>. - * - * APIs in this header should no longer be used. Direct - * use of the g_atomic APIs is preferred & existing code - * should be converted as needed. - */ - -#pragma once - -#include "internal.h" - -/** - * virAtomicIntCompareExchange: - * Compares atomic to oldval and, if equal, sets it to newval. If - * atomic was not equal to oldval then no change occurs. - * - * This compare and exchange is done atomically. - * - * Think of this operation as an atomic version of - * { if (*atomic == oldval) { *atomic = newval; return true; } - * else return false; } - * - * This call acts as a full compiler and hardware memory barrier. - */ -#define virAtomicIntCompareExchange(i, oldi, newi) \ - (!!g_atomic_int_compare_and_exchange(i, oldi, newi)) - -/** - * virAtomicIntAdd: - * Atomically adds val to the value of atomic. - * - * Think of this operation as an atomic version of - * { tmp = *atomic; *atomic += val; return tmp; } - * - * This call acts as a full compiler and hardware memory barrier. - */ -#define virAtomicIntAdd(i, v) g_atomic_int_add(i, v) - -/** - * virAtomicIntAnd: - * Performs an atomic bitwise 'and' of the value of atomic - * and val, storing the result back in atomic. - * - * This call acts as a full compiler and hardware memory barrier. - * - * Think of this operation as an atomic version of - * { tmp = *atomic; *atomic &= val; return tmp; } - */ -#define virAtomicIntAnd(i, v) g_atomic_int_and(i, v) - -/** - * virAtomicIntOr: - * Performs an atomic bitwise 'or' of the value of atomic - * and val, storing the result back in atomic. - * - * Think of this operation as an atomic version of - * { tmp = *atomic; *atomic |= val; return tmp; } - * - * This call acts as a full compiler and hardware memory barrier. - */ -#define virAtomicIntOr(i, v) g_atomic_int_or(i, v) - -/** - * virAtomicIntXor: - * Performs an atomic bitwise 'xor' of the value of atomic - * and val, storing the result back in atomic. - * - * Think of this operation as an atomic version of - * { tmp = *atomic; *atomic ^= val; return tmp; } - * - * This call acts as a full compiler and hardware memory barrier. - */ -#define virAtomicIntXor(i, v) g_atomic_int_xor(i, v) diff --git a/src/util/virobject.c b/src/util/virobject.c index 7749d89243..c71781550f 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -25,7 +25,6 @@ #include "virobject.h" #include "virthread.h" #include "viralloc.h" -#include "viratomic.h" #include "virerror.h" #include "virlog.h" #include "virprobe.h" diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 689db4f19d..23e149def4 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -57,7 +57,6 @@ # include <windows.h> #endif -#include "viratomic.h" #include "virprocess.h" #include "virerror.h" #include "viralloc.h" diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 6b47f4fa36..1d41ed34f7 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -25,7 +25,6 @@ #include "virsystemdpriv.h" #include "virsystemd.h" -#include "viratomic.h" #include "virbuffer.h" #include "virdbus.h" #include "virstring.h" -- 2.24.1

On Sat, Feb 01, 2020 at 07:33:49AM +0100, Michal Privoznik wrote:
Now, that every use of virAtomic was replaced with its g_atomic
s/,//
equivalent, let's remove the module.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- configure.ac | 1 - m4/virt-atomic.m4 | 77 -------------------------- src/Makefile.am | 6 --- src/libvirt_atomic.syms | 11 ---- src/libxl/libxl_domain.c | 1 - src/libxl/libxl_driver.c | 1 - src/lxc/lxc_process.c | 1 - src/nwfilter/nwfilter_dhcpsnoop.c | 1 - src/qemu/qemu_conf.c | 1 - src/qemu/qemu_domain.c | 1 - src/qemu/qemu_process.c | 1 - src/test/test_driver.c | 1 - src/util/Makefile.inc.am | 2 - src/util/viratomic.c | 35 ------------ src/util/viratomic.h | 90 ------------------------------- src/util/virobject.c | 1 - src/util/virprocess.c | 1 - src/util/virsystemd.c | 1 - 18 files changed, 233 deletions(-) delete mode 100644 m4/virt-atomic.m4 delete mode 100644 src/libvirt_atomic.syms delete mode 100644 src/util/viratomic.c delete mode 100644 src/util/viratomic.h
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Michal Privoznik