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;
101 auto &count = fReadersCount[local];
103 return reinterpret_cast<TVirtualRWMutex::Hint_t *
>(&count);
106 template <
typename MutexT>
109 std::unique_lock<MutexT> lock(mutex);
114 auto &count = fReadersCount[local];
116 return reinterpret_cast<TVirtualRWMutex::Hint_t *
>(&count);
119 template <
typename MutexT>
122 std::unique_lock<MutexT> lock(mutex);
127 fReadersCount[local] = newvalue;
139 fWriterThread = local;
152 template <
typename MutexT = ROOT::TSpinMutex,
typename RecurseCountsT = Internal::RecurseCounts>
170 void AssertReadCountLocIsFromCurrentThread(
const size_t* presumedLocalReadersCount);
178 TReentrantRWLock() : fReaders(0), fReaderReservation(0), fWriterReservation(0), fWriter(false) {}
180 TVirtualRWMutex::Hint_t *ReadLock();
181 void ReadUnLock(TVirtualRWMutex::Hint_t *);
182 TVirtualRWMutex::Hint_t *WriteLock();
183 void WriteUnLock(TVirtualRWMutex::Hint_t *);
185 std::unique_ptr<State> GetStateBefore();
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
Namespace for new ROOT classes and functions.
TReentrantRWLock()
Regular constructor.
TVirtualRWMutex::Hint_t Hint_t
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)
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::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 &)
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 &)
size_t & GetLocalReadersCount(local_t &local)
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)