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