diff options
author | Kuba Brecka <kuba.brecka@gmail.com> | 2015-12-01 13:11:42 +0000 |
---|---|---|
committer | Kuba Brecka <kuba.brecka@gmail.com> | 2015-12-01 13:11:42 +0000 |
commit | ac5f5d10d5e5975d1fdb1a48adf74bb600e8ab63 (patch) | |
tree | 44b44cd0a2a23ec655433ccf13e3c35d4acb2cdf | |
parent | 0d0692d854634b805734cd6681848df1302cbeef (diff) | |
download | bcm5719-llvm-ac5f5d10d5e5975d1fdb1a48adf74bb600e8ab63.tar.gz bcm5719-llvm-ac5f5d10d5e5975d1fdb1a48adf74bb600e8ab63.zip |
[tsan] Add interceptors and sychronization for libdispatch semaphores on OS X
This patch adds release and acquire semantics for libdispatch semaphores and a test case.
Differential Revision: http://reviews.llvm.org/D14992
llvm-svn: 254412
-rw-r--r-- | compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc | 17 | ||||
-rw-r--r-- | compiler-rt/test/tsan/Darwin/gcd-semaphore-norace.mm | 29 |
2 files changed, 46 insertions, 0 deletions
diff --git a/compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc b/compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc index aae199ba0f1..d388cf11431 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc @@ -25,6 +25,8 @@ #include <dispatch/dispatch.h> #include <pthread.h> +typedef long long_t; // NOLINT + namespace __tsan { typedef struct { @@ -166,6 +168,21 @@ TSAN_INTERCEPTOR(void, dispatch_once_f, dispatch_once_t *predicate, }); } +TSAN_INTERCEPTOR(long_t, dispatch_semaphore_signal, + dispatch_semaphore_t dsema) { + SCOPED_TSAN_INTERCEPTOR(dispatch_semaphore_signal, dsema); + Release(thr, pc, (uptr)dsema); + return REAL(dispatch_semaphore_signal)(dsema); +} + +TSAN_INTERCEPTOR(long_t, dispatch_semaphore_wait, dispatch_semaphore_t dsema, + dispatch_time_t timeout) { + SCOPED_TSAN_INTERCEPTOR(dispatch_semaphore_wait, dsema, timeout); + long_t result = REAL(dispatch_semaphore_wait)(dsema, timeout); + if (result == 0) Acquire(thr, pc, (uptr)dsema); + return result; +} + } // namespace __tsan #endif // SANITIZER_MAC diff --git a/compiler-rt/test/tsan/Darwin/gcd-semaphore-norace.mm b/compiler-rt/test/tsan/Darwin/gcd-semaphore-norace.mm new file mode 100644 index 00000000000..cd52a79ca65 --- /dev/null +++ b/compiler-rt/test/tsan/Darwin/gcd-semaphore-norace.mm @@ -0,0 +1,29 @@ +// RUN: %clang_tsan %s -o %t -framework Foundation +// RUN: %run %t 2>&1 + +#import <Foundation/Foundation.h> + +long global; + +int main() { + NSLog(@"Hello world."); + + global = 42; + + dispatch_semaphore_t sem = dispatch_semaphore_create(0); + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + + global = 43; + dispatch_semaphore_signal(sem); + }); + + dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); + global = 44; + + NSLog(@"Done."); + return 0; +} + +// CHECK: Hello world. +// CHECK: Done. +// CHECK-NOT: WARNING: ThreadSanitizer |