This converts the remaining files in libgomp/config/linux/ to use
atomics. gomp_init_thread_affinity fairly obviously needs no
barriers; I wasn't so sure about ptrlock, so tried without the
acquire/release barriers and found a number of the loop tests failed.
So it seems the usual lock barriers are needed. I also fixed a
slightly confusing use of compare_and_swap in gomp_ptrlock_set,
followed by an unconditional store in gomp_ptrlock_set_slow. If we're
going to write to the thing anyway, we may as well not use the compare
form.
Bootstrapped etc. powerpc-linux. I did see a libgomp testsuite
failure when testing this (pr51376), but virgin gcc also has the same
failure.
* config/linux/affinity.c: Use atomic rather than sync builtin.
* config/linux/lock.c: Likewise.
* config/linux/ptrlock.h: Likewise.
* config/linux/ptrlock.c: Likewise.
* config/linux/ptrlock.h (gomp_ptrlock_set): Always write here..
* config/linux/ptrlock.c (gomp_ptrlock_set_slow): ..not here.
* config/linux/futex.h (atomic_write_barrier): Delete unused function.
* config/linux/alpha/futex.h (atomic_write_barrier): Likewise.
* config/linux/ia64/futex.h (atomic_write_barrier): Likewise.
* config/linux/mips/futex.h (atomic_write_barrier): Likewise.
* config/linux/powerpc/futex.h (atomic_write_barrier): Likewise.
* config/linux/s390/futex.h (atomic_write_barrier): Likewise.
* config/linux/sparc/futex.h (atomic_write_barrier): Likewise.
* config/linux/x86/futex.h (atomic_write_barrier): Likewise.
Index: libgomp/config/linux/affinity.c
===
--- libgomp/config/linux/affinity.c (revision 181830)
+++ libgomp/config/linux/affinity.c (working copy)
@@ -109,7 +109,7 @@ gomp_init_thread_affinity (pthread_attr_
unsigned int cpu;
cpu_set_t cpuset;
- cpu = __sync_fetch_and_add (affinity_counter, 1);
+ cpu = __atomic_fetch_add (affinity_counter, 1, MEMMODEL_RELAXED);
cpu %= gomp_cpu_affinity_len;
CPU_ZERO (cpuset);
CPU_SET (gomp_cpu_affinity[cpu], cpuset);
Index: libgomp/config/linux/lock.c
===
--- libgomp/config/linux/lock.c (revision 181830)
+++ libgomp/config/linux/lock.c (working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2005, 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 2005, 2008, 2009, 2011 Free Software Foundation, Inc.
Contributed by Richard Henderson r...@redhat.com.
This file is part of the GNU OpenMP Library (libgomp).
@@ -62,7 +62,10 @@ gomp_unset_lock_30 (omp_lock_t *lock)
int
gomp_test_lock_30 (omp_lock_t *lock)
{
- return __sync_bool_compare_and_swap (lock, 0, 1);
+ int oldval = 0;
+
+ return __atomic_compare_exchange_n (lock, oldval, 1, false,
+ MEMMODEL_ACQUIRE, MEMMODEL_RELAXED);
}
void
@@ -104,11 +107,14 @@ int
gomp_test_nest_lock_30 (omp_nest_lock_t *lock)
{
void *me = gomp_icv (true);
+ int oldval;
if (lock-owner == me)
return ++lock-count;
- if (__sync_bool_compare_and_swap (lock-lock, 0, 1))
+ oldval = 0;
+ if (__atomic_compare_exchange_n (lock-lock, oldval, 1, false,
+ MEMMODEL_ACQUIRE, MEMMODEL_RELAXED))
{
lock-owner = me;
lock-count = 1;
@@ -184,8 +190,9 @@ gomp_set_nest_lock_25 (omp_nest_lock_25_
while (1)
{
- otid = __sync_val_compare_and_swap (lock-owner, 0, tid);
- if (otid == 0)
+ otid = 0;
+ if (__atomic_compare_exchange_n (lock-owner, otid, tid, false,
+ MEMMODEL_ACQUIRE, MEMMODEL_RELAXED))
{
lock-count = 1;
return;
@@ -207,7 +214,7 @@ gomp_unset_nest_lock_25 (omp_nest_lock_2
if (--lock-count == 0)
{
- __sync_lock_release (lock-owner);
+ __atomic_store_n (lock-owner, 0, MEMMODEL_RELEASE);
futex_wake (lock-owner, 1);
}
}
@@ -217,8 +224,9 @@ gomp_test_nest_lock_25 (omp_nest_lock_25
{
int otid, tid = gomp_tid ();
- otid = __sync_val_compare_and_swap (lock-owner, 0, tid);
- if (otid == 0)
+ otid = 0;
+ if (__atomic_compare_exchange_n (lock-owner, otid, tid, false,
+ MEMMODEL_ACQUIRE, MEMMODEL_RELAXED))
{
lock-count = 1;
return 1;
Index: libgomp/config/linux/ptrlock.h
===
--- libgomp/config/linux/ptrlock.h (revision 181830)
+++ libgomp/config/linux/ptrlock.h (working copy)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2008, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
Contributed by Jakub Jelinek ja...@redhat.com.
This file is part of the GNU OpenMP Library (libgomp).
@@ -24,7 +24,14 @@
/* This is a Linux specific implementation of a mutex synchronization
mechanism for libgomp. This type is private