Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMutex.cxx
Go to the documentation of this file.
1// @(#)root/thread:$Id$
2// Author: Fons Rademakers 26/06/97
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TMutex //
15// //
16// This class implements mutex locks. A mutex is a mutual exclusive //
17// lock. The actual work is done via the TMutexImp class (either //
18// TPosixMutex or TWin32Mutex). //
19// //
20//////////////////////////////////////////////////////////////////////////
21
22#include "TInterpreter.h"
23#include "TMutex.h"
24#include "TThreadFactory.h"
25#include <cerrno>
26#include "TError.h"
27
28
29////////////////////////////////////////////////////////////////////////////////
30/// Create a mutex lock. The actual mutex implementation will be
31/// provided via the TThreadFactory.
32
34{
36
37 if (!fMutexImp)
38 Error("TMutex", "could not create TMutexImp");
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Lock the mutex. Returns 0 when no error, EDEADLK when mutex was already
43/// locked by this thread and this mutex is not reentrant.
44
46{
48
49 return iret;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Try to lock mutex. Returns 0 when no error, EDEADLK when mutex was
54/// already locked by this thread and this mutex is not reentrant.
55
57{
59
60 return iret;
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Unlock the mutex. Returns 0 when no error, EPERM when mutex was already
65/// unlocked by this thread.
66
68{
69 return fMutexImp->UnLock();
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Clean up of mutex.
74
76{
77 return UnLock();
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Create mutex and return pointer to it. Calling function must care
82/// about proper deletion. The function is intended to be used in connection
83/// with the R__LOCKGUARD2 macro for local thread protection. Since "new" is
84/// used the TStorage class has to be protected by gGlobalMutex.
85
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
R__EXTERN TThreadFactory * gThreadFactory
virtual Int_t Lock()=0
virtual Int_t TryLock()=0
virtual Int_t UnLock()=0
TVirtualMutex * Factory(Bool_t recursive=kFALSE) override
Create mutex and return pointer to it.
Definition TMutex.cxx:86
Int_t CleanUp() override
Clean up of mutex.
Definition TMutex.cxx:75
Int_t UnLock() override
Unlock the mutex.
Definition TMutex.cxx:67
Int_t TryLock() override
Try to lock mutex.
Definition TMutex.cxx:56
TMutexImp * fMutexImp
Definition TMutex.h:36
TMutex(const TMutex &)=delete
Int_t Lock() override
Lock the mutex.
Definition TMutex.cxx:45
virtual TMutexImp * CreateMutexImp(Bool_t recursive)=0
This class implements a mutex interface.