2012-05-10 21:48:04 +08:00
|
|
|
//===-- tsan_clock.h --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// 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();
|
|
|
|
|
2012-05-11 22:42:24 +08:00
|
|
|
u64 get(unsigned tid) const {
|
2012-05-23 02:07:45 +08:00
|
|
|
DCHECK_LT(tid, kMaxTidInClock);
|
2012-05-10 21:48:04 +08:00
|
|
|
return clk_[tid];
|
|
|
|
}
|
|
|
|
|
2012-05-11 22:42:24 +08:00
|
|
|
void set(unsigned tid, u64 v) {
|
2012-05-23 02:07:45 +08:00
|
|
|
DCHECK_LT(tid, kMaxTid);
|
2012-11-07 23:08:20 +08:00
|
|
|
DCHECK_GE(v, clk_[tid]);
|
2012-05-10 21:48:04 +08:00
|
|
|
clk_[tid] = v;
|
2012-05-11 22:42:24 +08:00
|
|
|
if (nclk_ <= tid)
|
2012-05-10 21:48:04 +08:00
|
|
|
nclk_ = tid + 1;
|
|
|
|
}
|
|
|
|
|
2012-05-11 22:42:24 +08:00
|
|
|
void tick(unsigned tid) {
|
2012-05-23 02:07:45 +08:00
|
|
|
DCHECK_LT(tid, kMaxTid);
|
2012-05-10 21:48:04 +08:00
|
|
|
clk_[tid]++;
|
2012-05-11 22:42:24 +08:00
|
|
|
if (nclk_ <= tid)
|
2012-05-10 21:48:04 +08:00
|
|
|
nclk_ = tid + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uptr size() const {
|
|
|
|
return nclk_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void acquire(const SyncClock *src);
|
|
|
|
void release(SyncClock *dst) const;
|
|
|
|
void acq_rel(SyncClock *dst);
|
2012-07-28 23:27:41 +08:00
|
|
|
void ReleaseStore(SyncClock *dst) const;
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
uptr nclk_;
|
2012-05-17 22:17:51 +08:00
|
|
|
u64 clk_[kMaxTidInClock];
|
2012-05-10 21:48:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace __tsan
|
|
|
|
|
|
|
|
#endif // TSAN_CLOCK_H
|