public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use C11 atomics instead of atomic_bit_set/bit_test_set
@ 2022-09-05 16:35 Wilco Dijkstra
  2022-09-06 12:11 ` Florian Weimer
  0 siblings, 1 reply; 7+ messages in thread
From: Wilco Dijkstra @ 2022-09-05 16:35 UTC (permalink / raw)
  To: 'GNU C Library'; +Cc: Adhemerval Zanella


Replace the 3 uses of atomic_bit_set and atomic_bit_test_set with atomic_fetch_or_acquire.

Passes regress on AArch64.

---

diff --git a/nptl/nptl_free_tcb.c b/nptl/nptl_free_tcb.c
index 0d31143ac849de6398e06c399b94813ae57dcff3..0ba291e0d87435b7f551ab8d64f73fb5abec92fc 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_acquire (&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 870a8fcb34eb43b58c2260fee6a4624f0fbbd469..d206ed7bf4c2305c0d65bc2a47baefe02969e3d2 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_acquire (&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 39af275c254ef3e737736bd5c38099bada8746d6..7db1b71f1d5b6b6925a5405090a83697545b6798 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_acquire (&self->cancelhandling, EXITING_BITMASK);
 
   __pthread_unwind ((__pthread_unwind_buf_t *)
 		    THREAD_GETMEM (self, cleanup_jmp_buf));

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-09-13 10:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 16:35 [PATCH] Use C11 atomics instead of atomic_bit_set/bit_test_set Wilco Dijkstra
2022-09-06 12:11 ` Florian Weimer
2022-09-06 16:49   ` Wilco Dijkstra
2022-09-06 16:52     ` Wilco Dijkstra
2022-09-06 17:42       ` Florian Weimer
2022-09-06 18:41         ` [PATCH v2] " Wilco Dijkstra
2022-09-13 10:02           ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).