From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1895) id 974C3385354A; Tue, 6 Sep 2022 16:53:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 974C3385354A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1662483231; bh=mxmBuWxDBTgjU4zjbJw/+crqBC3nE0MiT0A6TEG6FD8=; h=From:To:Subject:Date:From; b=uI+NgrZj/w/Pg0L6r9q8I5EvgdFshT77Z8AvrXrHyfj3W7CeDfQjSo/MZPjgdSPWf M+vFZAP9g1P7nUIj2NdFPVoPV8tTlLNnrypF7NLAfwFatxxqvwBYihdqm6Neiqhu3+ FuGa7GF7RQgvbONr4xpmVU/6MRPFSWRHxoOnsq6E= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Wilco Dijkstra To: glibc-cvs@sourceware.org Subject: [glibc] malloc: Use C11 atomics rather than atomic_exchange_and_add X-Act-Checkin: glibc X-Git-Author: Wilco Dijkstra X-Git-Refname: refs/heads/master X-Git-Oldrev: 76fe56020e7ef354685b2284580ac1630c078a2b X-Git-Newrev: 89d40cacd0aed35e2546513ce01924b879523e46 Message-Id: <20220906165351.974C3385354A@sourceware.org> Date: Tue, 6 Sep 2022 16:53:51 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=89d40cacd0aed35e2546513ce01924b879523e46 commit 89d40cacd0aed35e2546513ce01924b879523e46 Author: Wilco Dijkstra Date: Tue Sep 6 16:49:01 2022 +0100 malloc: Use C11 atomics rather than atomic_exchange_and_add Replace a few counters using atomic_exchange_and_add with atomic_fetch_add_relaxed. Reviewed-by: Florian Weimer Diff: --- malloc/malloc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index 29fa71b3b2..ecec901b14 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;