Daily bump.
[official-gcc.git] / libsanitizer / tsan / tsan_clock.h
blob2ce480b2d16335c883649ba4155e1770e45f28c1
1 //===-- tsan_clock.h --------------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
9 //
10 //===----------------------------------------------------------------------===//
11 #ifndef TSAN_CLOCK_H
12 #define TSAN_CLOCK_H
14 #include "tsan_defs.h"
15 #include "tsan_vector.h"
17 namespace __tsan {
19 struct ClockElem {
20 u64 epoch : kClkBits;
21 u64 reused : 64 - kClkBits;
24 // The clock that lives in sync variables (mutexes, atomics, etc).
25 class SyncClock {
26 public:
27 SyncClock();
29 uptr size() const {
30 return clk_.Size();
33 u64 get(unsigned tid) const {
34 DCHECK_LT(tid, clk_.Size());
35 return clk_[tid].epoch;
38 void Reset();
40 void DebugDump(int(*printf)(const char *s, ...));
42 private:
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.
52 struct ThreadClock {
53 public:
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);
63 void set(u64 v) {
64 DCHECK_GE(v, clk_[tid_].epoch);
65 clk_[tid_].epoch = v;
68 void tick() {
69 clk_[tid_].epoch++;
72 uptr size() const {
73 return nclk_;
76 void acquire(const SyncClock *src);
77 void release(SyncClock *dst) const;
78 void acq_rel(SyncClock *dst);
79 void ReleaseStore(SyncClock *dst) const;
81 void DebugReset();
82 void DebugDump(int(*printf)(const char *s, ...));
84 private:
85 static const uptr kDirtyTids = SyncClock::kDirtyTids;
86 const unsigned tid_;
87 const unsigned reused_;
88 u64 last_acquire_;
89 uptr nclk_;
90 ClockElem clk_[kMaxTidInClock];
92 bool IsAlreadyAcquired(const SyncClock *src) const;
93 void UpdateCurrentThread(SyncClock *dst) const;
96 } // namespace __tsan
98 #endif // TSAN_CLOCK_H