[PATCH] D54664: [tsan] Add __cxa_guard_acquire hooks to support cooperative scheduling
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 20 10:24:30 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT347336: [tsan] Add __cxa_guard_acquire hooks to support cooperative scheduling (authored by vitalybuka, committed by ).
Herald added a subscriber: Sanitizers.
Changed prior to commit:
https://reviews.llvm.org/D54664?vs=174650&id=174808#toc
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D54664
Files:
lib/tsan/rtl/tsan_interceptors.cc
test/tsan/cxa_guard_acquire.cc
Index: lib/tsan/rtl/tsan_interceptors.cc
===================================================================
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -228,6 +228,16 @@
libignore()->OnLibraryLoaded(0);
}
+// The following two hooks can be used by for cooperative scheduling when
+// locking.
+#ifdef TSAN_EXTERNAL_HOOKS
+void OnPotentiallyBlockingRegionBegin();
+void OnPotentiallyBlockingRegionEnd();
+#else
+SANITIZER_WEAK_CXX_DEFAULT_IMPL void OnPotentiallyBlockingRegionBegin() {}
+SANITIZER_WEAK_CXX_DEFAULT_IMPL void OnPotentiallyBlockingRegionEnd() {}
+#endif
+
} // namespace __tsan
static ThreadSignalContext *SigCtx(ThreadState *thr) {
@@ -866,6 +876,8 @@
// Used in thread-safe function static initialization.
STDCXX_INTERCEPTOR(int, __cxa_guard_acquire, atomic_uint32_t *g) {
SCOPED_INTERCEPTOR_RAW(__cxa_guard_acquire, g);
+ OnPotentiallyBlockingRegionBegin();
+ auto on_exit = at_scope_exit(&OnPotentiallyBlockingRegionEnd);
for (;;) {
u32 cmp = atomic_load(g, memory_order_acquire);
if (cmp == 0) {
Index: test/tsan/cxa_guard_acquire.cc
===================================================================
--- test/tsan/cxa_guard_acquire.cc
+++ test/tsan/cxa_guard_acquire.cc
@@ -0,0 +1,25 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+
+namespace __tsan {
+
+void OnPotentiallyBlockingRegionBegin() {
+ printf("Enter __cxa_guard_acquire\n");
+}
+
+void OnPotentiallyBlockingRegionEnd() { printf("Exit __cxa_guard_acquire\n"); }
+
+} // namespace __tsan
+
+int main(int argc, char **argv) {
+ // CHECK: Enter main
+ printf("Enter main\n");
+ // CHECK-NEXT: Enter __cxa_guard_acquire
+ // CHECK-NEXT: Exit __cxa_guard_acquire
+ static int s = argc;
+ (void)s;
+ // CHECK-NEXT: Exit main
+ printf("Exit main\n");
+ return 0;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54664.174808.patch
Type: text/x-patch
Size: 1865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181120/b0805416/attachment.bin>
More information about the llvm-commits
mailing list