Skip to content

Commit a7f49e6

Browse files
authored
add tsan annotations (#490)
1 parent 4e5118b commit a7f49e6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/atomic.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919

2020
#include "driver_config.hpp"
2121

22+
#if !defined(THREAD_SANITIZER)
23+
#if defined(__has_feature)
24+
#if __has_feature(thread_sanitizer)
25+
#define THREAD_SANITIZER 1
26+
#endif
27+
#elif defined(__SANITIZE_THREAD__)
28+
#define THREAD_SANITIZER 1
29+
#endif
30+
#endif
31+
32+
// Annotations for atomic_thread_fence, see https://github.com/google/sanitizers/issues/1352
33+
#ifdef THREAD_SANITIZER
34+
extern "C" {
35+
void __tsan_acquire(void* addr);
36+
void __tsan_release(void* addr);
37+
}
38+
#endif
39+
2240
#if defined(HAVE_BOOST_ATOMIC)
2341
#include "atomic/atomic_boost.hpp"
2442
#elif defined(HAVE_STD_ATOMIC)

src/ref_counted.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ class RefCounted : public Allocated {
4343
assert(new_ref_count >= 1);
4444
if (new_ref_count == 1) {
4545
atomic_thread_fence(MEMORY_ORDER_ACQUIRE);
46+
#ifdef THREAD_SANITIZER
47+
__tsan_acquire(const_cast<void*>(static_cast<const void*>(this)));
48+
#endif
4649
delete static_cast<const T*>(this);
4750
}
4851
}

0 commit comments

Comments
 (0)