re PR sanitizer/55561 (TSAN: provide a TSAN instrumented libgomp)
authorDmitry Vyukov <dvyukov@gcc.gnu.org>
Thu, 31 Jan 2013 16:57:09 +0000 (08:57 -0800)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 31 Jan 2013 16:57:09 +0000 (17:57 +0100)
PR libgomp/55561
* config/linux/wait.h (do_spin): Use atomic load for addr.
* config/linux/ptrlock.c (gomp_ptrlock_get_slow): Use atomic
for intptr and ptrlock.
* config/linux/ptrlock.h (gomp_ptrlock_get): Use atomic load
for ptrlock.

Co-Authored-By: Joost VandeVondele <Joost.VandeVondele@mat.ethz.ch>
From-SVN: r195618

libgomp/ChangeLog
libgomp/config/linux/ptrlock.c
libgomp/config/linux/ptrlock.h
libgomp/config/linux/wait.h

index 266a66e..d765f8a 100644 (file)
@@ -1,3 +1,13 @@
+2013-01-31  Dmitry Vyukov  <dvyukov@gcc.gnu.org>
+           Joost VandeVondele  <Joost.VandeVondele@mat.ethz.ch>
+
+       PR libgomp/55561
+       * config/linux/wait.h (do_spin): Use atomic load for addr.
+       * config/linux/ptrlock.c (gomp_ptrlock_get_slow): Use atomic
+       for intptr and ptrlock.
+       * config/linux/ptrlock.h (gomp_ptrlock_get): Use atomic load
+       for ptrlock.
+
 2013-01-22  Alan Modra  <amodra@gmail.com>
 
        PR libgomp/51376
index 6a9ac47..fa51111 100644 (file)
@@ -50,9 +50,9 @@ gomp_ptrlock_get_slow (gomp_ptrlock_t *ptrlock)
 #endif
   do
     do_wait (intptr, 2);
-  while (*intptr == 2);
+  while (__atomic_load_n (intptr, MEMMODEL_RELAXED) == 2);
   __asm volatile ("" : : : "memory");
-  return *ptrlock;
+  return (void *) __atomic_load_n (ptrlock, MEMMODEL_ACQUIRE);
 }
 
 void
index ef23af7..8de1101 100644 (file)
@@ -48,8 +48,9 @@ static inline void *gomp_ptrlock_get (gomp_ptrlock_t *ptrlock)
 {
   uintptr_t oldval;
 
-  if ((uintptr_t) *ptrlock > 2)
-    return *ptrlock;
+  uintptr_t v = (uintptr_t) __atomic_load_n (ptrlock, MEMMODEL_ACQUIRE);
+  if (v > 2)
+    return (void *) v;
 
   oldval = 0;
   if (__atomic_compare_exchange_n (ptrlock, &oldval, 1, false,
index 8799042..e60f527 100644 (file)
@@ -51,7 +51,7 @@ static inline int do_spin (int *addr, int val)
   if (__builtin_expect (gomp_managed_threads > gomp_available_cpus, 0))
     count = gomp_throttled_spin_count_var;
   for (i = 0; i < count; i++)
-    if (__builtin_expect (*addr != val, 0))
+    if (__builtin_expect (__atomic_load_n (addr, MEMMODEL_RELAXED) != val, 0))
       return 0;
     else
       cpu_relax ();