Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:51

0001 // @(#)root/thread:$Id$
0002 // Authors: Enric Tejedor CERN  12/09/2016
0003 //          Philippe Canal FNAL 12/09/2016
0004 
0005 /*************************************************************************
0006  * Copyright (C) 1995-2016, Rene Brun and Fons Rademakers.               *
0007  * All rights reserved.                                                  *
0008  *                                                                       *
0009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0011  *************************************************************************/
0012 
0013 #ifndef ROOT_TRWSpinLock
0014 #define ROOT_TRWSpinLock
0015 
0016 #include "TSpinMutex.hxx"
0017 
0018 #include <atomic>
0019 #include <condition_variable>
0020 
0021 namespace ROOT {
0022 class TRWSpinLock {
0023 private:
0024    std::atomic<int> fReaders;           ///<! Number of readers
0025    std::atomic<int> fReaderReservation; ///<! A reader wants access
0026    std::atomic<int> fWriterReservation; ///<! A writer wants access
0027    std::atomic<bool> fWriter;           ///<! Is there a writer?
0028    ROOT::TSpinMutex fMutex;             ///<! RWlock internal mutex
0029    std::condition_variable_any fCond;   ///<! RWlock internal condition variable
0030 
0031 public:
0032    ////////////////////////////////////////////////////////////////////////
0033    /// Regular constructor.
0034    TRWSpinLock() : fReaders(0), fReaderReservation(0), fWriterReservation(0), fWriter(false) {}
0035 
0036    void ReadLock();
0037    void ReadUnLock();
0038    void WriteLock();
0039    void WriteUnLock();
0040 };
0041 
0042 class TRWSpinLockReadGuard {
0043 private:
0044    TRWSpinLock &fLock;
0045 
0046 public:
0047    TRWSpinLockReadGuard(TRWSpinLock &lock);
0048    ~TRWSpinLockReadGuard();
0049 };
0050 
0051 class TRWSpinLockWriteGuard {
0052 private:
0053    TRWSpinLock &fLock;
0054 
0055 public:
0056    TRWSpinLockWriteGuard(TRWSpinLock &lock);
0057    ~TRWSpinLockWriteGuard();
0058 };
0059 
0060 } // end of namespace ROOT
0061 
0062 #endif