Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add TVirtualRWMutex and TRWMutexImp
  • Loading branch information
pcanal committed Jun 22, 2017
commit ded122de0955425b4df90d6543fcbb6c43c45b14
1 change: 1 addition & 0 deletions core/base/inc/LinkDef3.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
#pragma link C++ class TFileCollection+;
#pragma link C++ class TVirtualAuth;
#pragma link C++ class TVirtualMutex;
#pragma link C++ class TVirtualRWMutex;
#pragma link C++ class TLockGuard;
#pragma link C++ class TRedirectOutputGuard;
#pragma link C++ class TVirtualPerfStats;
Expand Down
49 changes: 49 additions & 0 deletions core/base/inc/TVirtualRWMutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// @(#)root/base:$Id$
// Author: Philippe Canal, 2017

/*************************************************************************
* Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifndef ROOT_TVirtualRWMutex
#define ROOT_TVirtualRWMutex


//////////////////////////////////////////////////////////////////////////
// //
// TVirtualRWMutex //
// //
// This class implements a read-write mutex interface. The actual work //
// is done via TRWSpinLock which is available as soon as the thread //
// library is loaded. //
// //
//////////////////////////////////////////////////////////////////////////

#include "TVirtualMutex.h"


class TVirtualRWMutex : public TVirtualMutex {

public:
virtual void ReadLock() = 0;
virtual void ReadUnLock() = 0;
virtual void WriteLock() = 0;
virtual void WriteUnLock() = 0;

Int_t Lock() override { WriteLock(); return 1; }
Int_t TryLock() override { WriteLock(); return 1; }
Int_t UnLock() override { WriteUnLock(); return 1; }
Int_t CleanUp() override { WriteUnLock(); return 1; }

TVirtualRWMutex *Factory(Bool_t /*recursive*/ = kFALSE) override = 0;

ClassDefOverride(TVirtualRWMutex,0) // Virtual mutex lock class
};



#endif
2 changes: 1 addition & 1 deletion core/thread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ endif()

set(sources TCondition.cxx TConditionImp.cxx TMutex.cxx TMutexImp.cxx
TRWLock.cxx TRWSpinLock.cxx TSemaphore.cxx TThread.cxx TThreadFactory.cxx
TThreadImp.cxx)
TThreadImp.cxx TRWMutexImp.cxx)
if(NOT WIN32)
set(sources ${sources} TPosixCondition.cxx TPosixMutex.cxx
TPosixThread.cxx TPosixThreadFactory.cxx)
Expand Down
62 changes: 62 additions & 0 deletions core/thread/src/TRWMutexImp.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// @(#)root/thread:$Id$
// Author: Fons Rademakers 26/06/97

/*************************************************************************
* Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

//////////////////////////////////////////////////////////////////////////
// //
// TRWMutexImp //
// //
// This class implements the TVirtualRWMutex interface, //
// based on TRWSpinLock. //
// //
//////////////////////////////////////////////////////////////////////////

#include "TRWMutexImp.h"


////////////////////////////////////////////////////////////////////////////////
/// Take the Read Lock of the mutex.

void TRWMutexImp::ReadLock()
{
fMutexImp.ReadLock();
}

////////////////////////////////////////////////////////////////////////////////
/// Take the Write Lock of the mutex.

void TRWMutexImp::WriteLock()
{
fMutexImp.WriteLock();
}

////////////////////////////////////////////////////////////////////////////////
/// Release the read lock of the mutex

void TRWMutexImp::ReadUnLock()
{
fMutexImp.ReadUnLock();
}

////////////////////////////////////////////////////////////////////////////////
/// Release the read lock of the mutex

void TRWMutexImp::WriteUnLock()
{
fMutexImp.WriteUnLock();
}

////////////////////////////////////////////////////////////////////////////////
/// Create mutex and return pointer to it.

TVirtualRWMutex *TRWMutexImp::Factory(Bool_t /*recursive = kFALSE*/)
{
return new TRWMutexImp();
}
34 changes: 34 additions & 0 deletions core/thread/src/TRWMutexImp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Author: Philippe Canal, 2017

/*************************************************************************
* Copyright (C) 1995-2017, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifndef ROOT_TRWMutexImp
#define ROOT_TRWMutexImp

#include "TVirtualRWMutex.h"
#include "ROOT/TRWSpinLock.hxx"

#include "TBuffer.h" // Needed by ClassDEfInlineOverride

class TRWMutexImp : public TVirtualRWMutex {
ROOT::TRWSpinLock fMutexImp;

public:

void ReadLock() override;
void ReadUnLock() override;
void WriteLock() override;
void WriteUnLock() override;

TVirtualRWMutex *Factory(Bool_t /*recursive*/ = kFALSE) override;

ClassDefInlineOverride(TRWMutexImp,0) // Concrete RW mutex lock class
};

#endif