1349cc55cSDimitry Andric //===-- tsan_vector_clock.h -------------------------------------*- C++ -*-===// 2349cc55cSDimitry Andric // 3349cc55cSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4349cc55cSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5349cc55cSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6349cc55cSDimitry Andric // 7349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 8349cc55cSDimitry Andric // 9349cc55cSDimitry Andric // This file is a part of ThreadSanitizer (TSan), a race detector. 10349cc55cSDimitry Andric // 11349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 12349cc55cSDimitry Andric #ifndef TSAN_VECTOR_CLOCK_H 13349cc55cSDimitry Andric #define TSAN_VECTOR_CLOCK_H 14349cc55cSDimitry Andric 15349cc55cSDimitry Andric #include "tsan_defs.h" 16349cc55cSDimitry Andric 17349cc55cSDimitry Andric namespace __tsan { 18349cc55cSDimitry Andric 19349cc55cSDimitry Andric // Fixed-size vector clock, used both for threads and sync objects. 20349cc55cSDimitry Andric class VectorClock { 21349cc55cSDimitry Andric public: 22349cc55cSDimitry Andric VectorClock(); 23349cc55cSDimitry Andric 24349cc55cSDimitry Andric Epoch Get(Sid sid) const; 25349cc55cSDimitry Andric void Set(Sid sid, Epoch v); 26349cc55cSDimitry Andric 27349cc55cSDimitry Andric void Reset(); 28349cc55cSDimitry Andric void Acquire(const VectorClock* src); 29349cc55cSDimitry Andric void Release(VectorClock** dstp) const; 30349cc55cSDimitry Andric void ReleaseStore(VectorClock** dstp) const; 31349cc55cSDimitry Andric void ReleaseStoreAcquire(VectorClock** dstp); 32349cc55cSDimitry Andric void ReleaseAcquire(VectorClock** dstp); 33349cc55cSDimitry Andric 34349cc55cSDimitry Andric VectorClock& operator=(const VectorClock& other); 35349cc55cSDimitry Andric 36349cc55cSDimitry Andric private: 37*0fca6ea1SDimitry Andric VECTOR_ALIGNED Epoch clk_[kThreadSlotCount]; 38349cc55cSDimitry Andric }; 39349cc55cSDimitry Andric 40349cc55cSDimitry Andric ALWAYS_INLINE Epoch VectorClock::Get(Sid sid) const { 41349cc55cSDimitry Andric return clk_[static_cast<u8>(sid)]; 42349cc55cSDimitry Andric } 43349cc55cSDimitry Andric 44349cc55cSDimitry Andric ALWAYS_INLINE void VectorClock::Set(Sid sid, Epoch v) { 45349cc55cSDimitry Andric DCHECK_GE(v, clk_[static_cast<u8>(sid)]); 46349cc55cSDimitry Andric clk_[static_cast<u8>(sid)] = v; 47349cc55cSDimitry Andric } 48349cc55cSDimitry Andric 49349cc55cSDimitry Andric } // namespace __tsan 50349cc55cSDimitry Andric 51349cc55cSDimitry Andric #endif // TSAN_VECTOR_CLOCK_H 52