diff mbox series

[2/2] atomics: replace fetch-use-store with direct atomic operations

Message ID 20240701114230.193307-3-w.bumiller@proxmox.com (mailing list archive)
State New, archived
Headers show
Series change some odd-looking atomic uses | expand

Commit Message

Wolfgang Bumiller July 1, 2024, 11:42 a.m. UTC
Replaces the pattern `atomic_store(atomic_load() <op> something)`
pattern with its direct atomic function.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
Note: these previously used RELEASE ordering for the store and `relaxed`
ordering for the reads, while the replacement uses SEQ_CST, as there are no
other wrappers around yet.  Should we add `qatomic_fetch_{sub,and}_release`
variants?

 util/aio-posix.c | 3 +--
 util/aio-win32.c | 3 +--
 util/async.c     | 2 +-
 3 files changed, 3 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/util/aio-posix.c b/util/aio-posix.c
index 266c9dd35f..9cf7fed8fc 100644
--- a/util/aio-posix.c
+++ b/util/aio-posix.c
@@ -672,8 +672,7 @@  bool aio_poll(AioContext *ctx, bool blocking)
 
     if (use_notify_me) {
         /* Finish the poll before clearing the flag.  */
-        qatomic_store_release(&ctx->notify_me,
-                             qatomic_read(&ctx->notify_me) - 2);
+        qatomic_fetch_sub(&ctx->notify_me, 2);
     }
 
     aio_notify_accept(ctx);
diff --git a/util/aio-win32.c b/util/aio-win32.c
index d144f9391f..ff6d1ebf97 100644
--- a/util/aio-win32.c
+++ b/util/aio-win32.c
@@ -387,8 +387,7 @@  bool aio_poll(AioContext *ctx, bool blocking)
         ret = WaitForMultipleObjects(count, events, FALSE, timeout);
         if (blocking) {
             assert(first);
-            qatomic_store_release(&ctx->notify_me,
-                                  qatomic_read(&ctx->notify_me) - 2);
+            qatomic_fetch_sub(&ctx->notify_me, 2);
             aio_notify_accept(ctx);
         }
 
diff --git a/util/async.c b/util/async.c
index 0467890052..d17deeceea 100644
--- a/util/async.c
+++ b/util/async.c
@@ -330,7 +330,7 @@  aio_ctx_check(GSource *source)
     BHListSlice *s;
 
     /* Finish computing the timeout before clearing the flag.  */
-    qatomic_store_release(&ctx->notify_me, qatomic_read(&ctx->notify_me) & ~1);
+    qatomic_fetch_and(&ctx->notify_me, ~1);
     aio_notify_accept(ctx);
 
     QSLIST_FOREACH_RCU(bh, &ctx->bh_list, next) {