ROOT
v6-32
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 <errno.h>
26
#include "
TError.h
"
27
28
ClassImp
(
TMutex
);
29
30
////////////////////////////////////////////////////////////////////////////////
31
/// Create a mutex lock. The actual mutex implementation will be
32
/// provided via the TThreadFactory.
33
34
TMutex::TMutex
(
Bool_t
recursive)
35
{
36
fMutexImp
=
gThreadFactory
->CreateMutexImp(recursive);
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
46
Int_t
TMutex::Lock
()
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
57
Int_t
TMutex::TryLock
()
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
68
Int_t
TMutex::UnLock
()
69
{
70
return
fMutexImp
->UnLock();
71
}
72
73
////////////////////////////////////////////////////////////////////////////////
74
/// Clean up of mutex.
75
76
Int_t
TMutex::CleanUp
()
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
87
TVirtualMutex
*
TMutex::Factory
(
Bool_t
recursive)
88
{
89
TVirtualMutex
*ret =
new
TMutex
(recursive);
90
return
ret;
91
}
Bool_t
bool Bool_t
Definition
RtypesCore.h:63
Int_t
int Int_t
Definition
RtypesCore.h:45
ClassImp
#define ClassImp(name)
Definition
Rtypes.h:377
TError.h
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition
TError.cxx:185
TInterpreter.h
TMutex.h
TThreadFactory.h
gThreadFactory
R__EXTERN TThreadFactory * gThreadFactory
Definition
TThreadFactory.h:45
TMutex
Definition
TMutex.h:30
TMutex::Factory
TVirtualMutex * Factory(Bool_t recursive=kFALSE) override
Create mutex and return pointer to it.
Definition
TMutex.cxx:87
TMutex::CleanUp
Int_t CleanUp() override
Clean up of mutex.
Definition
TMutex.cxx:76
TMutex::UnLock
Int_t UnLock() override
Unlock the mutex.
Definition
TMutex.cxx:68
TMutex::TryLock
Int_t TryLock() override
Try to lock mutex.
Definition
TMutex.cxx:57
TMutex::fMutexImp
TMutexImp * fMutexImp
Definition
TMutex.h:36
TMutex::TMutex
TMutex(const TMutex &)=delete
TMutex::Lock
Int_t Lock() override
Lock the mutex.
Definition
TMutex.cxx:46
TVirtualMutex::TVirtualMutex
TVirtualMutex(Bool_t=kFALSE)
Definition
TVirtualMutex.h:35
core
thread
src
TMutex.cxx
ROOT v6-32 - Reference Guide Generated on Tue May 19 2026 02:46:46 (GVA Time) using Doxygen 1.13.2