From d1babeb32de5dae8893c640bd925357b218d846c Mon Sep 17 00:00:00 2001 From: Wilco Dijkstra Date: Thu, 22 Sep 2022 15:32:40 +0100 Subject: Use C11 atomics instead of atomic_increment(_val) Replace atomic_increment and atomic_increment_val with atomic_fetch_add_relaxed. One case in sem_post.c uses release semantics (see comment above it). The others are simple counters and do not protect any shared data from concurrent accesses. Passes regress on AArch64. Reviewed-by: Adhemerval Zanella --- nptl/nptl_setxid.c | 2 +- nptl/pthread_create.c | 2 +- nptl/sem_post.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'nptl') diff --git a/nptl/nptl_setxid.c b/nptl/nptl_setxid.c index e709822b9b..301809d200 100644 --- a/nptl/nptl_setxid.c +++ b/nptl/nptl_setxid.c @@ -163,7 +163,7 @@ setxid_signal_thread (struct xid_command *cmdp, struct pthread *t) /* If this failed, it must have had not started yet or else exited. */ if (!INTERNAL_SYSCALL_ERROR_P (val)) { - atomic_increment (&cmdp->cntr); + atomic_fetch_add_relaxed (&cmdp->cntr, 1); return 1; } else diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 59d8df8cd7..0df67484e2 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -759,7 +759,7 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr, we momentarily store a false value; this doesn't matter because there is no kosher thing a signal handler interrupting us right here can do that cares whether the thread count is correct. */ - atomic_increment (&__nptl_nthreads); + atomic_fetch_add_relaxed (&__nptl_nthreads, 1); /* Our local value of stopped_start and thread_ran can be accessed at any time. The PD->stopped_start may only be accessed if we have diff --git a/nptl/sem_post.c b/nptl/sem_post.c index 9e5741753a..7ec21e92eb 100644 --- a/nptl/sem_post.c +++ b/nptl/sem_post.c @@ -91,7 +91,7 @@ __old_sem_post (sem_t *sem) /* We must need to synchronize with consumers of this token, so the atomic increment must have release MO semantics. */ atomic_write_barrier (); - (void) atomic_increment_val (futex); + atomic_fetch_add_release (futex, 1); /* We always have to assume it is a shared semaphore. */ futex_wake (futex, 1, LLL_SHARED); return 0; -- cgit 1.4.1