File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010
1111#include " cinderx/python.h"
1212
13+ #if defined(__has_feature)
14+ #define CINDER_HAS_FEATURE (x ) __has_feature(x)
15+ #else
16+ #define CINDER_HAS_FEATURE (x ) 0
17+ #endif
18+
19+ #if defined(__SANITIZE_THREAD__) || CINDER_HAS_FEATURE(thread_sanitizer)
20+ #define CINDER_TSAN_ENABLED 1
21+ #else
22+ #define CINDER_TSAN_ENABLED 0
23+ #endif
24+
1325namespace cinderx {
1426
1527// Whether CinderX is being built with a debug build configuration.
Original file line number Diff line number Diff line change 66
77#include < cstddef>
88
9- #if defined(__has_feature)
10- #define CINDER_TSAN_HAS_FEATURE (x ) __has_feature(x)
11- #else
12- #define CINDER_TSAN_HAS_FEATURE (x ) 0
13- #endif
14-
15- #if defined(__SANITIZE_THREAD__) || CINDER_TSAN_HAS_FEATURE(thread_sanitizer)
16- #define CINDER_TSAN_ENABLED 1
17- #else
18- #define CINDER_TSAN_ENABLED 0
19- #endif
20-
219// JIT TSAN instrumentation is currently implemented for Linux x86-64. Other
2210// platforms can still use TSAN for non-JIT code.
2311#if CINDER_TSAN_ENABLED && defined(CINDER_X86_64) && defined(__linux__)
Original file line number Diff line number Diff line change 22
33#include " cinderx/Jit/compilation_lock.h"
44
5+ #include " cinderx/Common/define.h"
6+
7+ #if CINDER_TSAN_ENABLED
8+ #include < sanitizer/tsan_interface.h>
9+ #endif
10+
511#include < new>
612
713namespace cinderx ::jit {
814
15+ namespace {
16+
17+ void resetMutexAfterFork (std::recursive_mutex& mutex) {
18+ #if CINDER_TSAN_ENABLED
19+ void * native_mutex = mutex.native_handle ();
20+ __tsan_mutex_pre_unlock (native_mutex, __tsan_mutex_recursive_unlock);
21+ __tsan_mutex_post_unlock (native_mutex, 0 );
22+ __tsan_mutex_destroy (native_mutex, 0 );
23+ #endif
24+
25+ new (&mutex) std::recursive_mutex{};
26+
27+ #if CINDER_TSAN_ENABLED
28+ __tsan_mutex_create (mutex.native_handle (), __tsan_mutex_write_reentrant);
29+ #endif
30+ }
31+
32+ } // namespace
33+
934std::recursive_mutex& jitCompilationMutex () {
1035 static std::recursive_mutex mutex;
1136 return mutex;
@@ -26,7 +51,7 @@ void jitCompilationAtForkChild() {
2651 // across the fork, so unlock() would fail with EPERM and leave the lock held
2752 // forever. Destroying it isn't an option either, as it is still locked by
2853 // atForkPrepare(), so its lifetime ends without running its destructor.
29- new (& jitCompilationMutex ()) std::recursive_mutex{} ;
54+ resetMutexAfterFork ( jitCompilationMutex ());
3055}
3156
3257} // namespace cinderx::jit
You can’t perform that action at this time.
0 commit comments