Logo ROOT  
Reference Guide
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 <errno.h>
26#include "TError.h"
27
29
30////////////////////////////////////////////////////////////////////////////////
31/// Create a mutex lock. The actual mutex implementation will be
32/// provided via the TThreadFactory.
33
35{
37
38 if (!fMutexImp)
39 Error("TMutex", "could not create TMutexImp");
40}
41
42////////////////////////////////////////////////////////////////////////////////
43/// Lock the mutex. Returns 0 when no error, EDEADLK when mutex was already
44/// locked by this thread and this mutex is not reentrant.
45
47{
48 Int_t iret = fMutexImp->Lock();
49
50 return iret;
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Try to lock mutex. Returns 0 when no error, EDEADLK when mutex was
55/// already locked by this thread and this mutex is not reentrant.
56
58{
59 Int_t iret = fMutexImp->TryLock();
60
61 return iret;
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Unlock the mutex. Returns 0 when no error, EPERM when mutex was already
66/// unlocked by this thread.
67
69{
70 return fMutexImp->UnLock();
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Clean up of mutex.
75
77{
78 return UnLock();
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Create mutex and return pointer to it. Calling function must care
83/// about proper deletion. The function is intended to be used in connection
84/// with the R__LOCKGUARD2 macro for local thread protection. Since "new" is
85/// used the TStorage class has to be protected by gGlobalMutex.
86
88{
89 TVirtualMutex *ret = new TMutex(recursive);
90 return ret;
91}
int Int_t
Definition: RtypesCore.h:45
bool Bool_t
Definition: RtypesCore.h:63
#define ClassImp(name)
Definition: Rtypes.h:364
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:187
R__EXTERN TThreadFactory * gThreadFactory
virtual Int_t Lock()=0
virtual Int_t TryLock()=0
virtual Int_t UnLock()=0
Definition: TMutex.h:30
Int_t UnLock()
Unlock the mutex.
Definition: TMutex.cxx:68
Int_t CleanUp()
Clean up of mutex.
Definition: TMutex.cxx:76
TVirtualMutex * Factory(Bool_t recursive=kFALSE)
Create mutex and return pointer to it.
Definition: TMutex.cxx:87
Int_t Lock()
Lock the mutex.
Definition: TMutex.cxx:46
Int_t TryLock()
Try to lock mutex.
Definition: TMutex.cxx:57
TMutexImp * fMutexImp
Definition: TMutex.h:36
TMutex(const TMutex &)=delete
virtual TMutexImp * CreateMutexImp(Bool_t recursive)=0
This class implements a mutex interface.
Definition: TVirtualMutex.h:32