summaryrefslogtreecommitdiffstats
path: root/libsanitizer/tsan/tsan_clock.h
diff options
context:
space:
mode:
authorwmi <wmi@138bc75d-0d04-0410-961f-82ee72b054a4>2012-11-22 22:03:11 +0000
committerwmi <wmi@138bc75d-0d04-0410-961f-82ee72b054a4>2012-11-22 22:03:11 +0000
commit9cf754572854d9d9cd43c277eb7afb12e4911358 (patch)
treef83ad11b95452b47f813e942d24914f31a50394e /libsanitizer/tsan/tsan_clock.h
parentb077695d9e39a87da6f8bc68451a9d60467e7020 (diff)
downloadppe42-gcc-9cf754572854d9d9cd43c277eb7afb12e4911358.tar.gz
ppe42-gcc-9cf754572854d9d9cd43c277eb7afb12e4911358.zip
libsanitizer/
* tsan: New directory. Import tsan runtime from llvm. * configure.ac: Add 64 bits tsan build. * Makefile.am: Likewise. * configure: Regenerated. * Makefile.in: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@193737 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libsanitizer/tsan/tsan_clock.h')
-rw-r--r--libsanitizer/tsan/tsan_clock.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/libsanitizer/tsan/tsan_clock.h b/libsanitizer/tsan/tsan_clock.h
new file mode 100644
index 00000000000..d5c17305b31
--- /dev/null
+++ b/libsanitizer/tsan/tsan_clock.h
@@ -0,0 +1,80 @@
+//===-- tsan_clock.h --------------------------------------------*- C++ -*-===//
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is a part of ThreadSanitizer (TSan), a race detector.
+//
+//===----------------------------------------------------------------------===//
+#ifndef TSAN_CLOCK_H
+#define TSAN_CLOCK_H
+
+#include "tsan_defs.h"
+#include "tsan_vector.h"
+
+namespace __tsan {
+
+// The clock that lives in sync variables (mutexes, atomics, etc).
+class SyncClock {
+ public:
+ SyncClock();
+
+ uptr size() const {
+ return clk_.Size();
+ }
+
+ void Reset() {
+ clk_.Reset();
+ }
+
+ private:
+ Vector<u64> clk_;
+ friend struct ThreadClock;
+};
+
+// The clock that lives in threads.
+struct ThreadClock {
+ public:
+ ThreadClock();
+
+ u64 get(unsigned tid) const {
+ DCHECK_LT(tid, kMaxTidInClock);
+ return clk_[tid];
+ }
+
+ void set(unsigned tid, u64 v) {
+ DCHECK_LT(tid, kMaxTid);
+ DCHECK_GE(v, clk_[tid]);
+ clk_[tid] = v;
+ if (nclk_ <= tid)
+ nclk_ = tid + 1;
+ }
+
+ void tick(unsigned tid) {
+ DCHECK_LT(tid, kMaxTid);
+ clk_[tid]++;
+ if (nclk_ <= tid)
+ nclk_ = tid + 1;
+ }
+
+ void Disable(unsigned tid);
+
+ uptr size() const {
+ return nclk_;
+ }
+
+ void acquire(const SyncClock *src);
+ void release(SyncClock *dst) const;
+ void acq_rel(SyncClock *dst);
+ void ReleaseStore(SyncClock *dst) const;
+
+ private:
+ uptr nclk_;
+ u64 clk_[kMaxTidInClock];
+};
+
+} // namespace __tsan
+
+#endif // TSAN_CLOCK_H
OpenPOWER on IntegriCloud