d: Fix accesses of immutable arrays using constant index still bounds checked
[official-gcc.git] / libsanitizer / tsan / tsan_vector_clock.h
blob63b206302190d18215a1f2a6426dd36610813a4a
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.
11 //===----------------------------------------------------------------------===//
12 #ifndef TSAN_VECTOR_CLOCK_H
13 #define TSAN_VECTOR_CLOCK_H
15 #include "tsan_defs.h"
17 namespace __tsan {
19 // Fixed-size vector clock, used both for threads and sync objects.
20 class VectorClock {
21 public:
22 VectorClock();
24 Epoch Get(Sid sid) const;
25 void Set(Sid sid, Epoch v);
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);
34 VectorClock& operator=(const VectorClock& other);
36 private:
37 Epoch clk_[kThreadSlotCount] VECTOR_ALIGNED;
40 ALWAYS_INLINE Epoch VectorClock::Get(Sid sid) const {
41 return clk_[static_cast<u8>(sid)];
44 ALWAYS_INLINE void VectorClock::Set(Sid sid, Epoch v) {
45 DCHECK_GE(v, clk_[static_cast<u8>(sid)]);
46 clk_[static_cast<u8>(sid)] = v;
49 } // namespace __tsan
51 #endif // TSAN_VECTOR_CLOCK_H