From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1895) id 3451938582BF; Fri, 9 Sep 2022 14:04:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3451938582BF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1662732282; bh=tmrtRmtk67mWAcQnusm35kbSArIH6V56L6iGyEtfV+4=; h=From:To:Subject:Date:From; b=FuIsky44JYdEHh6dB1bjyaDKzzrZwfvEy8loxMHX2G4Ww5H3FULc6DugIIy3QN22m JtgNncSMY8W72ZVQ8Qd8TFr2s3L2unLKe747r0cj8wJ7aBdHW9M3hSGcR+t6LB+NHL kc41gRFbZzpAPO/Dnr+IGaVzU/JQXvlwOZ0jiWFE= 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] Use C11 atomics instead atomic_add(_zero) X-Act-Checkin: glibc X-Git-Author: Wilco Dijkstra X-Git-Refname: refs/heads/master X-Git-Oldrev: 83859e1115269cf56d21669361d4ddbe2687831c X-Git-Newrev: 53b251c9ff03ab59ba58fcddb9dc97c69f25fadc Message-Id: <20220909140442.3451938582BF@sourceware.org> Date: Fri, 9 Sep 2022 14:04:42 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=53b251c9ff03ab59ba58fcddb9dc97c69f25fadc commit 53b251c9ff03ab59ba58fcddb9dc97c69f25fadc Author: Wilco Dijkstra Date: Fri Sep 9 14:11:23 2022 +0100 Use C11 atomics instead atomic_add(_zero) Replace atomic_add and atomic_add_zero with atomic_fetch_add_relaxed. Reviewed-by: DJ Delorie Diff: --- malloc/malloc.c | 2 +- sysdeps/unix/sysv/linux/check_pf.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/malloc/malloc.c b/malloc/malloc.c index ecec901b14..aea4993f1b 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -3034,7 +3034,7 @@ munmap_chunk (mchunkptr p) malloc_printerr ("munmap_chunk(): invalid pointer"); atomic_decrement (&mp_.n_mmaps); - atomic_add (&mp_.mmapped_mem, -total_size); + atomic_fetch_add_relaxed (&mp_.mmapped_mem, -total_size); /* If munmap failed the process virtual memory address space is in a bad shape. Just leave the block hanging around, the process will diff --git a/sysdeps/unix/sysv/linux/check_pf.c b/sysdeps/unix/sysv/linux/check_pf.c index fe73fe3ba8..4d486ca9b5 100644 --- a/sysdeps/unix/sysv/linux/check_pf.c +++ b/sysdeps/unix/sysv/linux/check_pf.c @@ -278,7 +278,7 @@ make_request (int fd, pid_t pid) { free (result); - atomic_add (&noai6ai_cached.usecnt, 2); + atomic_fetch_add_relaxed (&noai6ai_cached.usecnt, 2); noai6ai_cached.seen_ipv4 = seen_ipv4; noai6ai_cached.seen_ipv6 = seen_ipv6; result = &noai6ai_cached; @@ -349,7 +349,7 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6, *in6ai = data->in6ai; if (olddata != NULL && olddata->usecnt > 0 - && atomic_add_zero (&olddata->usecnt, -1)) + && atomic_fetch_add_relaxed (&olddata->usecnt, -1) == 1) free (olddata); return; @@ -377,7 +377,7 @@ __free_in6ai (struct in6addrinfo *ai) (struct cached_data *) ((char *) ai - offsetof (struct cached_data, in6ai)); - if (atomic_add_zero (&data->usecnt, -1)) + if (atomic_fetch_add_relaxed (&data->usecnt, -1) == 1) { __libc_lock_lock (lock);