2013-06-12 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libsanitizer / tsan / tsan_clock.h
blob8e4bf99ca89629488c458ae9b7cfcb7255221d55
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 // The clock that lives in sync variables (mutexes, atomics, etc).
20 class SyncClock {
21 public:
22 SyncClock();
24 uptr size() const {
25 return clk_.Size();
28 void Reset() {
29 clk_.Reset();
32 private:
33 Vector<u64> clk_;
34 friend struct ThreadClock;
37 // The clock that lives in threads.
38 struct ThreadClock {
39 public:
40 ThreadClock();
42 u64 get(unsigned tid) const {
43 DCHECK_LT(tid, kMaxTidInClock);
44 return clk_[tid];
47 void set(unsigned tid, u64 v) {
48 DCHECK_LT(tid, kMaxTid);
49 DCHECK_GE(v, clk_[tid]);
50 clk_[tid] = v;
51 if (nclk_ <= tid)
52 nclk_ = tid + 1;
55 void tick(unsigned tid) {
56 DCHECK_LT(tid, kMaxTid);
57 clk_[tid]++;
58 if (nclk_ <= tid)
59 nclk_ = tid + 1;
62 uptr size() const {
63 return nclk_;
66 void acquire(const SyncClock *src);
67 void release(SyncClock *dst) const;
68 void acq_rel(SyncClock *dst);
69 void ReleaseStore(SyncClock *dst) const;
71 private:
72 uptr nclk_;
73 u64 clk_[kMaxTidInClock];
76 } // namespace __tsan
78 #endif // TSAN_CLOCK_H