4 #include <sanitizer/tsan_interface.h>
6 // A very primitive mutex annotated with tsan annotations.
9 Mutex(bool prof
, unsigned create_flags
, unsigned destroy_flags
=0)
13 , destroy_flags_(destroy_flags
) {
14 __tsan_mutex_create(this, create_flags
);
18 __tsan_mutex_destroy(this, destroy_flags_
);
22 __tsan_mutex_pre_lock(this, 0);
24 __tsan_mutex_post_lock(this, 0, 0);
28 __tsan_mutex_pre_lock(this, __tsan_mutex_try_lock
);
29 bool ok
= TryLockImpl();
30 __tsan_mutex_post_lock(this, __tsan_mutex_try_lock
|
31 (ok
? 0 : __tsan_mutex_try_lock_failed
), 0);
36 __tsan_mutex_pre_unlock(this, 0);
38 __tsan_mutex_post_unlock(this, 0);
42 for (int seq
= seq_
; seq
== seq_
;) {
50 __tsan_mutex_pre_signal(this, 0);
54 __tsan_mutex_post_signal(this, 0);
59 std::atomic
<bool> locked_
;
61 unsigned destroy_flags_
;
63 // This models mutex profiling subsystem.
64 static Mutex prof_mu_
;
65 static int prof_data_
;
67 void LockImpl(bool prof
= true) {
68 while (!TryLockImpl())
75 return !locked_
.exchange(true);
83 // This happens inside of mutex lock annotations.
84 __tsan_mutex_pre_divert(this, 0);
88 __tsan_mutex_post_divert(this, 0);
92 Mutex
Mutex::prof_mu_(false, __tsan_mutex_linker_init
);
93 int Mutex::prof_data_
;