Logo ROOT   6.14/05
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.
34  TRWSpinLock() : fReaders(0), fReaderReservation(0), fWriterReservation(0), fWriter(false) {}
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
void WriteUnLock()
Release the lock in write mode.
std::condition_variable_any fCond
! RWlock internal condition variable
Definition: TRWSpinLock.hxx:29
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
ROOT::TSpinMutex fMutex
! RWlock internal mutex
Definition: TRWSpinLock.hxx:28
std::atomic< int > fReaderReservation
! A reader wants access
Definition: TRWSpinLock.hxx:25
std::atomic< bool > fWriter
! Is there a writer?
Definition: TRWSpinLock.hxx:27
std::atomic< int > fReaders
! Number of readers
Definition: TRWSpinLock.hxx:24
A spin mutex class which respects the STL interface for mutexes.
Definition: TSpinMutex.hxx:40
void WriteLock()
Acquire the lock in write mode.
Definition: TRWSpinLock.cxx:77
void ReadLock()
Acquire the lock in read mode.
Definition: TRWSpinLock.cxx:35
TRWSpinLock()
Regular constructor.
Definition: TRWSpinLock.hxx:34
std::atomic< int > fWriterReservation
! A writer wants access
Definition: TRWSpinLock.hxx:26
void ReadUnLock()
Release the lock in read mode.
Definition: TRWSpinLock.cxx:61