Logo ROOT   6.10/09
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 
22 namespace ROOT {
23  class TRWSpinLock {
24  private:
25  std::atomic<int> fReaders; ///<! Number of readers
26  std::atomic<int> fReaderReservation; ///<! A reader wants access
27  std::atomic<int> fWriterReservation; ///<! A writer wants access
28  std::atomic<bool> fWriter; ///<! Is there a writer?
29  ROOT::TSpinMutex fMutex; ///<! RWlock internal mutex
30  std::condition_variable_any fCond; ///<! RWlock internal condition variable
31 
32  public:
33  ////////////////////////////////////////////////////////////////////////
34  /// Regular constructor.
35  TRWSpinLock() : fReaders(0), fReaderReservation(0), fWriterReservation(0), fWriter(false) {}
36 
37  void ReadLock();
38  void ReadUnLock();
39  void WriteLock();
40  void WriteUnLock();
41  };
42 } // end of namespace ROOT
43 
44 #endif
void WriteUnLock()
Release the lock in write mode.
std::condition_variable_any fCond
! RWlock internal condition variable
Definition: TRWSpinLock.hxx:30
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
ROOT::TSpinMutex fMutex
! RWlock internal mutex
Definition: TRWSpinLock.hxx:29
std::atomic< int > fReaderReservation
! A reader wants access
Definition: TRWSpinLock.hxx:26
std::atomic< bool > fWriter
! Is there a writer?
Definition: TRWSpinLock.hxx:28
std::atomic< int > fReaders
! Number of readers
Definition: TRWSpinLock.hxx:25
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:35
std::atomic< int > fWriterReservation
! A writer wants access
Definition: TRWSpinLock.hxx:27
void ReadUnLock()
Release the lock in read mode.
Definition: TRWSpinLock.cxx:61