13#ifndef ROOT_TReentrantRWLock
14#define ROOT_TReentrantRWLock
21#include <condition_variable>
23#include <unordered_map>
28 using Hint_t = TVirtualRWMutex::Hint_t;
47 return reinterpret_cast<TVirtualRWMutex::Hint_t *
>(&(local->
fReadersCount));
50 template <
typename MutexT>
57 return reinterpret_cast<TVirtualRWMutex::Hint_t *
>(&(local->
fReadersCount));
60 template <
typename MutexT>
89 using Hint_t = TVirtualRWMutex::Hint_t;
103 return reinterpret_cast<TVirtualRWMutex::Hint_t *
>(&count);
106 template <
typename MutexT>
109 std::unique_lock<MutexT> lock(mutex);
116 return reinterpret_cast<TVirtualRWMutex::Hint_t *
>(&count);
119 template <
typename MutexT>
122 std::unique_lock<MutexT> lock(mutex);
152template <
typename MutexT = ROOT::TSpinMutex,
typename RecurseCountsT = Internal::RecurseCounts>
180 TVirtualRWMutex::Hint_t *
ReadLock();
186 std::unique_ptr<StateDelta>
Rewind(
const State &earlierState);
187 void Apply(std::unique_ptr<StateDelta> &&delta);
std::condition_variable_any fCond
! RWlock internal condition variable
void WriteUnLock(TVirtualRWMutex::Hint_t *)
Release the lock in write mode.
TVirtualRWMutex::State State
std::atomic< int > fReaderReservation
! A reader wants access
std::unique_ptr< StateDelta > Rewind(const State &earlierState)
Rewind to an earlier mutex state, returning the delta.
TVirtualRWMutex::Hint_t * ReadLock()
Acquire the lock in read mode.
RecurseCountsT fRecurseCounts
! Trackers for re-entry in the lock by the same thread.
TVirtualRWMutex::Hint_t * WriteLock()
Acquire the lock in write mode.
std::atomic< bool > fWriter
! Is there a writer?
std::atomic< int > fReaders
! Number of readers
void ReadUnLock(TVirtualRWMutex::Hint_t *)
Release the lock in read mode.
void AssertReadCountLocIsFromCurrentThread(const size_t *presumedLocalReadersCount)
Assert that presumedLocalReadersCount really matches the local read count.
MutexT fMutex
! RWlock internal mutex
std::unique_ptr< State > GetStateBefore()
Get the lock state before the most recent write lock was taken.
TReentrantRWLock()
Regular constructor.
void Apply(std::unique_ptr< StateDelta > &&delta)
Re-apply a delta.
std::atomic< int > fWriterReservation
! A writer wants access
Namespace for new ROOT classes and functions.
Hint_t * DecrementReadCount(local_t &local)
size_t fWriteRecurse
! Number of re-entry in the lock by the same thread.
Hint_t * DecrementReadCount(local_t &local, MutexT &mutex)
bool IsNotCurrentWriter(local_t &local) const
std::unordered_map< std::thread::id, size_t > ReaderColl_t
bool IsCurrentWriter(local_t &local) const
void ResetIsWriter(local_t &)
std::thread::id fWriterThread
! Holder of the write lock
void DecrementWriteCount()
TVirtualRWMutex::Hint_t Hint_t
Hint_t * IncrementReadCount(local_t &local)
void ResetReadCount(local_t &local, int newvalue)
ReaderColl_t fReadersCount
! Set of reader thread ids
Hint_t * IncrementReadCount(local_t &local, MutexT &mutex)
size_t & GetLocalReadersCount(local_t &local)
void SetIsWriter(local_t &local)
bool IsCurrentWriter(local_t &local)
Hint_t * DecrementReadCount(local_t &local)
bool IsNotCurrentWriter(local_t &local)
Hint_t * IncrementReadCount(local_t &local, MutexT &)
void ResetReadCount(local_t &local, int newvalue)
TVirtualRWMutex::Hint_t Hint_t
void DecrementWriteCount()
void ResetIsWriter(local_t &local)
Hint_t * IncrementReadCount(local_t &local)
Hint_t * DecrementReadCount(local_t &local, MutexT &)
size_t & GetLocalReadersCount(local_t &local)
void SetIsWriter(local_t &local)
size_t fWriteRecurse
! Number of re-entry in the lock by the same thread.
State as returned by GetStateDelta() that can be passed to Restore()
Earlier lock state as returned by GetState() that can be passed to Restore()