From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1895) id B10403858C53; Tue, 13 Sep 2022 14:59:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B10403858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663081148; bh=7VZPmhvBmYglBcmUv+yaeRgORdYpV/97zpdFzglIMUM=; h=From:To:Subject:Date:From; b=qDE2oU+iCtfJPHwEa0HeZ0rG+AGzR3zLWg0b9luC2qVpU7OPhAuLc7LXGzcCgAFXL dhPH77uUC1NRIRzsuMuxamrvVa7tYIzRaEQh67TbZWbZfcRet1V6+AwgYYO+n6NFdd sd+MY4RjGqEfdGZCEoiI40mPiNYnm2VPS76x+klI= 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 relaxed atomics since there is no MO dependence X-Act-Checkin: glibc X-Git-Author: Wilco Dijkstra X-Git-Refname: refs/heads/master X-Git-Oldrev: f278835f594740f5913001430641cf1da4878670 X-Git-Newrev: a30e960328fc60e066967d1224ecd5b6e173cda3 Message-Id: <20220913145908.B10403858C53@sourceware.org> Date: Tue, 13 Sep 2022 14:59:08 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a30e960328fc60e066967d1224ecd5b6e173cda3 commit a30e960328fc60e066967d1224ecd5b6e173cda3 Author: Wilco Dijkstra Date: Tue Sep 13 11:58:07 2022 +0100 Use relaxed atomics since there is no MO dependence Replace the 3 uses of atomic_bit_set and atomic_bit_test_set with atomic_fetch_or_relaxed. Using relaxed MO is correct since the atomics are used to ensure memory is released only once. Reviewed-by: Florian Weimer Diff: --- nptl/nptl_free_tcb.c | 3 ++- nptl/pthread_create.c | 2 +- sysdeps/nptl/pthreadP.h | 8 +------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/nptl/nptl_free_tcb.c b/nptl/nptl_free_tcb.c index 0d31143ac8..86a8904898 100644 --- a/nptl/nptl_free_tcb.c +++ b/nptl/nptl_free_tcb.c @@ -24,7 +24,8 @@ void __nptl_free_tcb (struct pthread *pd) { /* The thread is exiting now. */ - if (atomic_bit_test_set (&pd->cancelhandling, TERMINATED_BIT) == 0) + if ((atomic_fetch_or_relaxed (&pd->cancelhandling, TERMINATED_BITMASK) + & TERMINATED_BITMASK) == 0) { /* Free TPP data. */ if (pd->tpp != NULL) diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index e7e4ede6b2..ee29cb375d 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -487,7 +487,7 @@ start_thread (void *arg) /* The thread is exiting now. Don't set this bit until after we've hit the event-reporting breakpoint, so that td_thr_get_info on us while at the breakpoint reports TD_THR_RUN state rather than TD_THR_ZOMBIE. */ - atomic_bit_set (&pd->cancelhandling, EXITING_BIT); + atomic_fetch_or_relaxed (&pd->cancelhandling, EXITING_BITMASK); if (__glibc_unlikely (atomic_decrement_and_test (&__nptl_nthreads))) /* This was the last thread. */ diff --git a/sysdeps/nptl/pthreadP.h b/sysdeps/nptl/pthreadP.h index 39af275c25..c8521b0b23 100644 --- a/sysdeps/nptl/pthreadP.h +++ b/sysdeps/nptl/pthreadP.h @@ -43,12 +43,6 @@ atomic_compare_and_exchange_val_acq (&(descr)->member, new, old) #endif -#ifndef THREAD_ATOMIC_BIT_SET -# define THREAD_ATOMIC_BIT_SET(descr, member, bit) \ - atomic_bit_set (&(descr)->member, bit) -#endif - - static inline short max_adaptive_count (void) { #if HAVE_TUNABLES @@ -276,7 +270,7 @@ __do_cancel (void) struct pthread *self = THREAD_SELF; /* Make sure we get no more cancellations. */ - atomic_bit_set (&self->cancelhandling, EXITING_BIT); + atomic_fetch_or_relaxed (&self->cancelhandling, EXITING_BITMASK); __pthread_unwind ((__pthread_unwind_buf_t *) THREAD_GETMEM (self, cleanup_jmp_buf));