mirror of
git://sourceware.org/git/glibc.git
synced 2026-10-30 21:07:53 +08:00
Add missing compiler barriers to include/atomic.h (bug 34748)
Barriers were missing from atomic_forced_read, atomic_load_relaxed,
atomic_store_relaxed. The easiest way to get them is to use volatile
accesses.
This was observed as a test hang in nptl/tst-rwlock9. The test
ended up spinning in __pthread_rwlock_rdlock_full64:
/* We still need to wait for explicit hand-over, but we must
not use futex_wait anymore because we would just time out
in this case and thus make the spin-waiting we need
unnecessarily expensive. */
while ((atomic_load_relaxed (&rwlock->__data.__wrphase_futex)
| PTHREAD_RWLOCK_FUTEX_USED)
== (1 | PTHREAD_RWLOCK_FUTEX_USED))
{
/* TODO Back-off? */
}
GCC hoisted the load out of the loop.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
This commit is contained in:
+4
-8
@@ -520,8 +520,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#ifndef atomic_forced_read
|
#ifndef atomic_forced_read
|
||||||
# define atomic_forced_read(x) \
|
# define atomic_forced_read(x) (*((volatile __typeof (x) *) &(x)))
|
||||||
({ __typeof (x) __x; __asm ("" : "=r" (__x) : "0" (x)); __x; })
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This is equal to 1 iff the architecture supports 64b atomic operations. */
|
/* This is equal to 1 iff the architecture supports 64b atomic operations. */
|
||||||
@@ -666,10 +665,7 @@ void __atomic_link_error (void);
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
# ifndef atomic_load_relaxed
|
# ifndef atomic_load_relaxed
|
||||||
# define atomic_load_relaxed(mem) \
|
# define atomic_load_relaxed(mem) (*((volatile __typeof (*mem) *) (mem)))
|
||||||
({ __typeof ((__typeof (*(mem))) *(mem)) __atg100_val; \
|
|
||||||
__asm ("" : "=r" (__atg100_val) : "0" (*(mem))); \
|
|
||||||
__atg100_val; })
|
|
||||||
# endif
|
# endif
|
||||||
# ifndef atomic_load_acquire
|
# ifndef atomic_load_acquire
|
||||||
# define atomic_load_acquire(mem) \
|
# define atomic_load_acquire(mem) \
|
||||||
@@ -679,8 +675,8 @@ void __atomic_link_error (void);
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
# ifndef atomic_store_relaxed
|
# ifndef atomic_store_relaxed
|
||||||
/* XXX Use inline asm here? */
|
# define atomic_store_relaxed(mem, val) \
|
||||||
# define atomic_store_relaxed(mem, val) do { *(mem) = (val); } while (0)
|
do { *((volatile __typeof (*mem) *) (mem)) = (val); } while (0)
|
||||||
# endif
|
# endif
|
||||||
# ifndef atomic_store_release
|
# ifndef atomic_store_release
|
||||||
# define atomic_store_release(mem, val) \
|
# define atomic_store_release(mem, val) \
|
||||||
|
|||||||
Reference in New Issue
Block a user