[compiler-rt] r191946 - tsan: fix a bug in pthread_once when called from an ignored library
Dmitry Vyukov
dvyukov at google.com
Fri Oct 4 03:27:21 PDT 2013
Author: dvyukov
Date: Fri Oct 4 05:27:21 2013
New Revision: 191946
URL: http://llvm.org/viewvc/llvm-project?rev=191946&view=rev
Log:
tsan: fix a bug in pthread_once when called from an ignored library
It must set thr->in_rtl = 0 before executing user callback.
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=191946&r1=191945&r2=191946&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Fri Oct 4 05:27:21 2013
@@ -1181,7 +1181,9 @@ TSAN_INTERCEPTOR(int, pthread_barrier_wa
}
TSAN_INTERCEPTOR(int, pthread_once, void *o, void (*f)()) {
- SCOPED_TSAN_INTERCEPTOR(pthread_once, o, f);
+ SCOPED_INTERCEPTOR_RAW(pthread_once, o, f);
+ // Using SCOPED_INTERCEPTOR_RAW, because if we are called from an ignored lib,
+ // the user callback must be executed with thr->in_rtl == 0.
if (o == 0 || f == 0)
return EINVAL;
atomic_uint32_t *a = static_cast<atomic_uint32_t*>(o);
@@ -1193,14 +1195,16 @@ TSAN_INTERCEPTOR(int, pthread_once, void
(*f)();
CHECK_EQ(thr->in_rtl, 0);
thr->in_rtl = old_in_rtl;
- Release(thr, pc, (uptr)o);
+ if (!thr->in_ignored_lib)
+ Release(thr, pc, (uptr)o);
atomic_store(a, 2, memory_order_release);
} else {
while (v != 2) {
pthread_yield();
v = atomic_load(a, memory_order_acquire);
}
- Acquire(thr, pc, (uptr)o);
+ if (!thr->in_ignored_lib)
+ Acquire(thr, pc, (uptr)o);
}
return 0;
}
More information about the llvm-commits
mailing list