Logo ROOT  
Reference Guide
TRWSpinLock.hxx
Go to the documentation of this file.
1 // @(#)root/thread:$Id$
2 // Authors: Enric Tejedor CERN 12/09/2016
3 // Philippe Canal FNAL 12/09/2016
4 
5 /*************************************************************************
6  * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers. *
7  * All rights reserved. *
8  * *
9  * For the licensing terms see $ROOTSYS/LICENSE. *
10  * For the list of contributors see $ROOTSYS/README/CREDITS. *
11  *************************************************************************/
12 
13 #ifndef ROOT_TRWSpinLock
14 #define ROOT_TRWSpinLock
15 
16 #include "TSpinMutex.hxx"
17 
18 #include <atomic>
19 #include <condition_variable>
20 
21 namespace ROOT {
22 class TRWSpinLock {
23 private:
24  std::atomic<int> fReaders; ///<! Number of readers
25  std::atomic<int> fReaderReservation; ///<! A reader wants access
26  std::atomic<int> fWriterReservation; ///<! A writer wants access
27  std::atomic<bool> fWriter; ///<! Is there a writer?
28  ROOT::TSpinMutex fMutex; ///<! RWlock internal mutex
29  std::condition_variable_any fCond; ///<! RWlock internal condition variable
30 
31 public:
32  ////////////////////////////////////////////////////////////////////////
33  /// Regular constructor.
35 
36  void ReadLock();
37  void ReadUnLock();
38  void WriteLock();
39  void WriteUnLock();
40 };
41 
43 private:
45 
46 public:
49 };
50 
52 private:
54 
55 public:
58 };
59 
60 } // end of namespace ROOT
61 
62 #endif
ROOT::TRWSpinLock::WriteUnLock
void WriteUnLock()
Release the lock in write mode.
Definition: TRWSpinLock.cxx:102
ROOT::TSpinMutex
A spin mutex class which respects the STL interface for mutexes.
Definition: TSpinMutex.hxx:42
ROOT::TRWSpinLockReadGuard::fLock
TRWSpinLock & fLock
Definition: TRWSpinLock.hxx:44
TSpinMutex.hxx
ROOT::TRWSpinLock::TRWSpinLock
TRWSpinLock()
Regular constructor.
Definition: TRWSpinLock.hxx:34
ROOT::TRWSpinLock::fWriterReservation
std::atomic< int > fWriterReservation
! A writer wants access
Definition: TRWSpinLock.hxx:26
ROOT::TRWSpinLock::fReaderReservation
std::atomic< int > fReaderReservation
! A reader wants access
Definition: TRWSpinLock.hxx:25
ROOT::TRWSpinLockReadGuard::TRWSpinLockReadGuard
TRWSpinLockReadGuard(TRWSpinLock &lock)
Definition: TRWSpinLock.cxx:114
ROOT::TRWSpinLockWriteGuard::fLock
TRWSpinLock & fLock
Definition: TRWSpinLock.hxx:53
ROOT::TRWSpinLock::fCond
std::condition_variable_any fCond
! RWlock internal condition variable
Definition: TRWSpinLock.hxx:29
ROOT::TRWSpinLockWriteGuard
Definition: TRWSpinLock.hxx:51
ROOT::TRWSpinLock::ReadUnLock
void ReadUnLock()
Release the lock in read mode.
Definition: TRWSpinLock.cxx:61
ROOT::TRWSpinLockReadGuard
Definition: TRWSpinLock.hxx:42
ROOT::TRWSpinLock::fWriter
std::atomic< bool > fWriter
! Is there a writer?
Definition: TRWSpinLock.hxx:27
ROOT::TRWSpinLockWriteGuard::TRWSpinLockWriteGuard
TRWSpinLockWriteGuard(TRWSpinLock &lock)
Definition: TRWSpinLock.cxx:124
ROOT::TRWSpinLock::ReadLock
void ReadLock()
Acquire the lock in read mode.
Definition: TRWSpinLock.cxx:35
ROOT::TRWSpinLock
Definition: TRWSpinLock.hxx:22
ROOT::TRWSpinLock::fReaders
std::atomic< int > fReaders
! Number of readers
Definition: TRWSpinLock.hxx:24
ROOT::TRWSpinLockWriteGuard::~TRWSpinLockWriteGuard
~TRWSpinLockWriteGuard()
Definition: TRWSpinLock.cxx:129
ROOT::TRWSpinLockReadGuard::~TRWSpinLockReadGuard
~TRWSpinLockReadGuard()
Definition: TRWSpinLock.cxx:119
ROOT::TRWSpinLock::fMutex
ROOT::TSpinMutex fMutex
! RWlock internal mutex
Definition: TRWSpinLock.hxx:28
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::TRWSpinLock::WriteLock
void WriteLock()
Acquire the lock in write mode.
Definition: TRWSpinLock.cxx:77