1 //===-- tsan_clock.h --------------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
10 //===----------------------------------------------------------------------===//
14 #include "tsan_defs.h"
15 #include "tsan_vector.h"
21 u64 reused
: 64 - kClkBits
;
24 // The clock that lives in sync variables (mutexes, atomics, etc).
33 u64
get(unsigned tid
) const {
34 DCHECK_LT(tid
, clk_
.Size());
35 return clk_
[tid
].epoch
;
40 void DebugDump(int(*printf
)(const char *s
, ...));
43 unsigned release_store_tid_
;
44 unsigned release_store_reused_
;
45 static const uptr kDirtyTids
= 2;
46 unsigned dirty_tids_
[kDirtyTids
];
47 mutable Vector
<ClockElem
> clk_
;
48 friend struct ThreadClock
;
51 // The clock that lives in threads.
54 explicit ThreadClock(unsigned tid
, unsigned reused
= 0);
56 u64
get(unsigned tid
) const {
57 DCHECK_LT(tid
, kMaxTidInClock
);
58 return clk_
[tid
].epoch
;
61 void set(unsigned tid
, u64 v
);
64 DCHECK_GE(v
, clk_
[tid_
].epoch
);
76 void acquire(const SyncClock
*src
);
77 void release(SyncClock
*dst
) const;
78 void acq_rel(SyncClock
*dst
);
79 void ReleaseStore(SyncClock
*dst
) const;
82 void DebugDump(int(*printf
)(const char *s
, ...));
85 static const uptr kDirtyTids
= SyncClock::kDirtyTids
;
87 const unsigned reused_
;
90 ClockElem clk_
[kMaxTidInClock
];
92 bool IsAlreadyAcquired(const SyncClock
*src
) const;
93 void UpdateCurrentThread(SyncClock
*dst
) const;
98 #endif // TSAN_CLOCK_H