1//===-- tsan_vector_clock.h -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of ThreadSanitizer (TSan), a race detector.
10//
11//===----------------------------------------------------------------------===//
12#ifndef TSAN_VECTOR_CLOCK_H
13#define TSAN_VECTOR_CLOCK_H
14
15#include "tsan_defs.h"
16
17namespace __tsan {
18
19// Fixed-size vector clock, used both for threads and sync objects.
20class VectorClock {
21 public:
22 VectorClock();
23
24 Epoch Get(Sid sid) const;
25 void Set(Sid sid, Epoch v);
26
27 void Reset();
28 void Acquire(const VectorClock* src);
29 void Release(VectorClock** dstp) const;
30 void ReleaseStore(VectorClock** dstp) const;
31 void ReleaseStoreAcquire(VectorClock** dstp);
32 void ReleaseAcquire(VectorClock** dstp);
33
34 VectorClock& operator=(const VectorClock& other);
35
36 private:
37 Epoch clk_[kThreadSlotCount] VECTOR_ALIGNED;
38};
39
40ALWAYS_INLINE Epoch VectorClock::Get(Sid sid) const {
41 return clk_[static_cast<u8>(sid)];
42}
43
44ALWAYS_INLINE void VectorClock::Set(Sid sid, Epoch v) {
45 DCHECK_GE(v, clk_[static_cast<u8>(sid)]);
46 clk_[static_cast<u8>(sid)] = v;
47}
48
49} // namespace __tsan
50
51#endif // TSAN_VECTOR_CLOCK_H
52

source code of compiler-rt/lib/tsan/rtl/tsan_vector_clock.h