11 #include <mach/mach_time.h>
14 // TSan-invisible barrier.
15 // Tests use it to establish necessary execution order in a way that does not
16 // interfere with tsan (does not establish synchronization between threads).
17 typedef unsigned long long invisible_barrier_t
;
22 void __tsan_testonly_barrier_init(invisible_barrier_t
*barrier
,
24 void __tsan_testonly_barrier_wait(invisible_barrier_t
*barrier
);
29 static inline void barrier_init(invisible_barrier_t
*barrier
, unsigned count
) {
30 __tsan_testonly_barrier_init(barrier
, count
);
33 static inline void barrier_wait(invisible_barrier_t
*barrier
) {
34 __tsan_testonly_barrier_wait(barrier
);
37 // Default instance of the barrier, but a test can declare more manually.
38 invisible_barrier_t barrier
;
40 void print_address(const char *str
, int n
, ...) {
41 fprintf(stderr
, "%s", str
);
45 void *p
= va_arg(ap
, void *);
46 #if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__)
47 // On FreeBSD, the %p conversion specifier works as 0x%x and thus does not
48 // match to the format used in the diagnotic message.
49 fprintf(stderr
, "0x%012lx ", (unsigned long) p
);
50 #elif defined(__mips64)
51 fprintf(stderr
, "0x%010lx ", (unsigned long) p
);
54 fprintf(stderr
, "\n");
58 unsigned long long monotonic_clock_ns() {
59 static mach_timebase_info_data_t timebase_info
;
60 if (timebase_info
.denom
== 0) mach_timebase_info(&timebase_info
);
61 return (mach_absolute_time() * timebase_info
.numer
) / timebase_info
.denom
;
64 unsigned long long monotonic_clock_ns() {
66 clock_gettime(CLOCK_MONOTONIC
, &t
);
67 return (unsigned long long)t
.tv_sec
* 1000000000ull + t
.tv_nsec
;
71 //The const kPCInc must be in sync with StackTrace::GetPreviousInstructionPc
72 #if defined(__powerpc64__)
73 // PCs are always 4 byte aligned.
75 #elif defined(__sparc__) || defined(__mips__)
85 void AnnotateRWLockCreate(const char *f
, int l
, void *m
);
86 void AnnotateRWLockCreateStatic(const char *f
, int l
, void *m
);
87 void AnnotateRWLockDestroy(const char *f
, int l
, void *m
);
88 void AnnotateRWLockAcquired(const char *f
, int l
, void *m
, long is_w
);
89 void AnnotateRWLockReleased(const char *f
, int l
, void *m
, long is_w
);
95 #define ANNOTATE_RWLOCK_CREATE(m) \
96 AnnotateRWLockCreate(__FILE__, __LINE__, m)
97 #define ANNOTATE_RWLOCK_CREATE_STATIC(m) \
98 AnnotateRWLockCreateStatic(__FILE__, __LINE__, m)
99 #define ANNOTATE_RWLOCK_DESTROY(m) \
100 AnnotateRWLockDestroy(__FILE__, __LINE__, m)
101 #define ANNOTATE_RWLOCK_ACQUIRED(m, is_w) \
102 AnnotateRWLockAcquired(__FILE__, __LINE__, m, is_w)
103 #define ANNOTATE_RWLOCK_RELEASED(m, is_w) \
104 AnnotateRWLockReleased(__FILE__, __LINE__, m, is_w)