diff mbox series

malloc: Use C11 atomics rather than atomic_exchange_and_add

Message ID AS4PR08MB79018CFAC25E187364C30921837F9@AS4PR08MB7901.eurprd08.prod.outlook.com
State New
Headers show
Series malloc: Use C11 atomics rather than atomic_exchange_and_add | expand

Commit Message

Wilco Dijkstra Sept. 5, 2022, 4:14 p.m. UTC
Replace a few counters using atomic_exchange_and_add with atomic_fetch_add_relaxed.

Passes regress on AArch64.

---

Comments

Florian Weimer Sept. 6, 2022, 12:03 p.m. UTC | #1
* Wilco Dijkstra via Libc-alpha:

> Replace a few counters using atomic_exchange_and_add with atomic_fetch_add_relaxed.

Line is overly long.

Patch looks okay to me (relative to what we had before).

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Thanks,
Florian
diff mbox series

Patch

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 29fa71b3b2a3d0a671149eaf619e4d518c56aef5..ecec901b14f602e3c93da1a847f043ffee41a1f4 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -2460,11 +2460,11 @@  sysmalloc_mmap (INTERNAL_SIZE_T nb, size_t pagesize, int extra_flags, mstate av)
     }
 
   /* update statistics */
-  int new = atomic_exchange_and_add (&mp_.n_mmaps, 1) + 1;
+  int new = atomic_fetch_add_relaxed (&mp_.n_mmaps, 1) + 1;
   atomic_max (&mp_.max_n_mmaps, new);
 
   unsigned long sum;
-  sum = atomic_exchange_and_add (&mp_.mmapped_mem, size) + size;
+  sum = atomic_fetch_add_relaxed (&mp_.mmapped_mem, size) + size;
   atomic_max (&mp_.max_mmapped_mem, sum);
 
   check_chunk (av, p);
@@ -3084,7 +3084,7 @@  mremap_chunk (mchunkptr p, size_t new_size)
   set_head (p, (new_size - offset) | IS_MMAPPED);
 
   INTERNAL_SIZE_T new;
-  new = atomic_exchange_and_add (&mp_.mmapped_mem, new_size - size - offset)
+  new = atomic_fetch_add_relaxed (&mp_.mmapped_mem, new_size - size - offset)
         + new_size - size - offset;
   atomic_max (&mp_.max_mmapped_mem, new);
   return p;