tsan_vector_clock.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "tsan_defs.h"
  15. namespace __tsan {
  16. // Fixed-size vector clock, used both for threads and sync objects.
  17. class VectorClock {
  18. public:
  19. VectorClock();
  20. Epoch Get(Sid sid) const;
  21. void Set(Sid sid, Epoch v);
  22. void Reset();
  23. void Acquire(const VectorClock* src);
  24. void Release(VectorClock** dstp) const;
  25. void ReleaseStore(VectorClock** dstp) const;
  26. void ReleaseStoreAcquire(VectorClock** dstp);
  27. void ReleaseAcquire(VectorClock** dstp);
  28. VectorClock& operator=(const VectorClock& other);
  29. private:
  30. Epoch clk_[kThreadSlotCount] VECTOR_ALIGNED;
  31. };
  32. ALWAYS_INLINE Epoch VectorClock::Get(Sid sid) const {
  33. return clk_[static_cast<u8>(sid)];
  34. }
  35. ALWAYS_INLINE void VectorClock::Set(Sid sid, Epoch v) {
  36. DCHECK_GE(v, clk_[static_cast<u8>(sid)]);
  37. clk_[static_cast<u8>(sid)] = v;
  38. }
  39. } // namespace __tsan
  40. #endif // TSAN_VECTOR_CLOCK_H