[compiler-rt] r204654 - tsan: use read lock instead of write in atomic operations when possible

Dmitry Vyukov dvyukov at google.com
Mon Mar 24 11:51:13 PDT 2014


Author: dvyukov
Date: Mon Mar 24 13:51:13 2014
New Revision: 204654

URL: http://llvm.org/viewvc/llvm-project?rev=204654&view=rev
Log:
tsan: use read lock instead of write in atomic operations when possible

Modified:
    compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc

Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc?rev=204654&r1=204653&r2=204654&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interface_atomic.cc Mon Mar 24 13:51:13 2014
@@ -455,8 +455,9 @@ static bool AtomicCAS(ThreadState *thr,
   (void)fmo;  // Unused because llvm does not pass it yet.
   MemoryWriteAtomic(thr, pc, (uptr)a, SizeLog<T>());
   SyncVar *s = 0;
+  bool write_lock = mo != mo_acquire && mo != mo_consume;
   if (mo != mo_relaxed) {
-    s = ctx->synctab.GetOrCreateAndLock(thr, pc, (uptr)a, true);
+    s = ctx->synctab.GetOrCreateAndLock(thr, pc, (uptr)a, write_lock);
     thr->fast_state.IncrementEpoch();
     // Can't increment epoch w/o writing to the trace as well.
     TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0);
@@ -469,8 +470,12 @@ static bool AtomicCAS(ThreadState *thr,
   }
   T cc = *c;
   T pr = func_cas(a, cc, v);
-  if (s)
-    s->mtx.Unlock();
+  if (s) {
+    if (write_lock)
+      s->mtx.Unlock();
+    else
+      s->mtx.ReadUnlock();
+  }
   if (pr == cc)
     return true;
   *c = pr;





More information about the llvm-commits mailing list