13 #ifndef ROOT_TRWSpinLock 14 #define ROOT_TRWSpinLock 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);
152 template <
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::thread::id fWriterThread
! Holder of the write lock
MutexT fMutex
! RWlock internal mutex
void SetIsWriter(local_t &local)
std::atomic< int > fReaderReservation
! A reader wants access
void ReadUnLock(TVirtualRWMutex::Hint_t *)
Release the lock in read mode.
Namespace for new ROOT classes and functions.
void AssertReadCountLocIsFromCurrentThread(const size_t *presumedLocalReadersCount)
Assert that presumedLocalReadersCount really matches the local read count.
TReentrantRWLock()
Regular constructor.
TVirtualRWMutex::State State
TVirtualRWMutex::Hint_t Hint_t
std::unique_ptr< State > GetStateBefore()
Get the lock state before the most recent write lock was taken.
void SetIsWriter(local_t &local)
std::unordered_map< std::thread::id, size_t > ReaderColl_t
TVirtualRWMutex::Hint_t Hint_t
void ResetReadCount(local_t &local, int newvalue)
void WriteUnLock(TVirtualRWMutex::Hint_t *)
Release the lock in write mode.
Hint_t * DecrementReadCount(local_t &local)
Hint_t * DecrementReadCount(local_t &local)
ReaderColl_t fReadersCount
! Set of reader thread ids
std::atomic< int > fWriterReservation
! A writer wants access
Hint_t * IncrementReadCount(local_t &local)
std::unique_ptr< StateDelta > Rewind(const State &earlierState)
Rewind to an earlier mutex state, returning the delta.
std::condition_variable_any fCond
! RWlock internal condition variable
size_t fWriteRecurse
! Number of re-entry in the lock by the same thread.
Hint_t * IncrementReadCount(local_t &local)
Hint_t * DecrementReadCount(local_t &local, MutexT &)
void Apply(std::unique_ptr< StateDelta > &&delta)
Re-apply a delta.
size_t & GetLocalReadersCount(local_t &local)
bool IsNotCurrentWriter(local_t &local) const
RecurseCountsT fRecurseCounts
! Trackers for re-entry in the lock by the same thread.
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()
bool IsCurrentWriter(local_t &local) const
Hint_t * IncrementReadCount(local_t &local, MutexT &)
TVirtualRWMutex::Hint_t * ReadLock()
Acquire the lock in read mode.
size_t & GetLocalReadersCount(local_t &local)
TVirtualRWMutex::Hint_t * WriteLock()
Acquire the lock in write mode.
void ResetIsWriter(local_t &local)
Earlier lock state as returned by GetState() that can be passed to Restore()
std::atomic< bool > fWriter
! Is there a writer?
void DecrementWriteCount()
void ResetReadCount(local_t &local, int newvalue)
Hint_t * IncrementReadCount(local_t &local, MutexT &mutex)
std::atomic< int > fReaders
! Number of readers
void ResetIsWriter(local_t &)
void DecrementWriteCount()
bool IsCurrentWriter(local_t &local)
bool IsNotCurrentWriter(local_t &local)
Hint_t * DecrementReadCount(local_t &local, MutexT &mutex)