Logo ROOT  
Reference Guide
TRWMutexImp.cxx
Go to the documentation of this file.
1// @(#)root/thread:$Id$
2// Author: Fons Rademakers 26/06/97
3
4/*************************************************************************
5 * Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TRWMutexImp //
15// //
16// This class implements the TVirtualRWMutex interface, //
17// based on TRWSpinLock. //
18// //
19//////////////////////////////////////////////////////////////////////////
20
21#include "TRWMutexImp.h"
22#include "ROOT/TSpinMutex.hxx"
23#include "TMutex.h"
24
25namespace ROOT {
26
27////////////////////////////////////////////////////////////////////////////////
28/// Take the Read Lock of the mutex.
29
30template <typename MutexT, typename RecurseCountsT>
32{
33 return fMutexImp.ReadLock();
34}
35
36////////////////////////////////////////////////////////////////////////////////
37/// Take the Write Lock of the mutex.
38
39template <typename MutexT, typename RecurseCountsT>
41{
42 return fMutexImp.WriteLock();
43}
44
45////////////////////////////////////////////////////////////////////////////////
46/// Release the read lock of the mutex
47
48template <typename MutexT, typename RecurseCountsT>
49void TRWMutexImp<MutexT, RecurseCountsT>::ReadUnLock(TVirtualRWMutex::Hint_t *hint)
50{
51 fMutexImp.ReadUnLock(hint);
52}
53
54////////////////////////////////////////////////////////////////////////////////
55/// Release the read lock of the mutex
56
57template <typename MutexT, typename RecurseCountsT>
58void TRWMutexImp<MutexT, RecurseCountsT>::WriteUnLock(TVirtualRWMutex::Hint_t *hint)
59{
60 fMutexImp.WriteUnLock(hint);
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Create mutex and return pointer to it.
65
66template <typename MutexT, typename RecurseCountsT>
68{
69 return new TRWMutexImp();
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Restore the mutex state to `state`. This function must only be called while
74/// the mutex is locked. Returns the DeltaState between now and the resulting
75/// state (i.e. lock count before state), such that the difference can be
76/// re-applied using `Apply()`.
77/// In pseudo-code:
78/// delta = current_lock_count - earlierState.lock_count;
79/// current_lock_count -= delta;
80/// return delta;
81
82template <typename MutexT, typename RecurseCountsT>
83std::unique_ptr<TVirtualRWMutex::StateDelta>
85{
86 return fMutexImp.Rewind(earlierState);
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Apply the mutex state delta.
91/// In pseudo-code:
92/// current_lock_count += delta;
93
94template <typename MutexT, typename RecurseCountsT>
95void TRWMutexImp<MutexT, RecurseCountsT>::Apply(std::unique_ptr<TVirtualRWMutex::StateDelta> &&delta)
96{
97 fMutexImp.Apply(std::move(delta));
98}
99
100////////////////////////////////////////////////////////////////////////////////
101/// Get the mutex state *before* the current lock was taken. This function must
102/// only be called while the mutex is locked.
103
104template <typename MutexT, typename RecurseCountsT>
105std::unique_ptr<TVirtualRWMutex::State>
107{
108 return fMutexImp.GetStateBefore();
109}
110
111template class TRWMutexImp<TMutex>;
112template class TRWMutexImp<ROOT::TSpinMutex>;
113template class TRWMutexImp<std::mutex>;
116
117} // End of namespace ROOT
bool Bool_t
Definition: RtypesCore.h:59
void Apply(std::unique_ptr< StateDelta > &&delta) override
Apply the mutex state delta.
Definition: TRWMutexImp.cxx:95
void WriteUnLock(Hint_t *) override
Release the read lock of the mutex.
Definition: TRWMutexImp.cxx:58
std::unique_ptr< StateDelta > Rewind(const State &earlierState) override
Restore the mutex state to state.
Definition: TRWMutexImp.cxx:84
Hint_t * WriteLock() override
Take the Write Lock of the mutex.
Definition: TRWMutexImp.cxx:40
std::unique_ptr< State > GetStateBefore() override
Get the mutex state before the current lock was taken.
Hint_t * ReadLock() override
Take the Read Lock of the mutex.
Definition: TRWMutexImp.cxx:31
TVirtualRWMutex * Factory(Bool_t=kFALSE) override
Create mutex and return pointer to it.
Definition: TRWMutexImp.cxx:67
void ReadUnLock(Hint_t *) override
Release the read lock of the mutex.
Definition: TRWMutexImp.cxx:49
VSD Structures.
Definition: StringConv.hxx:21
Earlier lock state as returned by GetState() that can be passed to Restore()