ROOTANA
Loading...
Searching...
No Matches
libNetDirectory
RootLock.cxx
Go to the documentation of this file.
1
/********************************************************************\
2
3
Name: RootLock.cxx
4
Created by: Konstantin Olchanski
5
6
Contents: Helper functions for locking ROOT access in multithreaded network servers
7
8
$Id$
9
10
\********************************************************************/
11
12
#include "
RootLock.h
"
13
14
#include <TSemaphore.h>
15
#include <TTimer.h>
16
#include <TThread.h>
17
18
static
TSemaphore
gRootSema
(0);
// wait by server, post by timer
19
static
TSemaphore
gWaitSema
(0);
// post by server, wait by timer
20
static
TSemaphore
gDoneSema
(0);
// post by server, wait by timer
21
22
bool
gDebugLockRoot
=
false
;
23
24
void
LockRoot
()
25
{
26
if
(
gDebugLockRoot
)
27
printf(
"Try Lock ROOT!\n"
);
28
gWaitSema
.Post();
29
gRootSema
.Wait();
30
if
(
gDebugLockRoot
)
31
printf(
"Lock ROOT!\n"
);
32
}
33
34
void
UnlockRoot
()
35
{
36
if
(
gDebugLockRoot
)
37
printf(
"Unlock ROOT!\n"
);
38
gDoneSema
.Post();
39
}
40
41
LockRootGuard::LockRootGuard
()
// ctor
42
{
43
fLocked
=
true
;
44
LockRoot
();
45
}
46
47
LockRootGuard::~LockRootGuard
()
// dtor
48
{
49
if
(
fLocked
)
50
Unlock
();
51
}
52
53
void
LockRootGuard::Unlock
()
54
{
55
UnlockRoot
();
56
fLocked
=
false
;
57
}
58
59
class
ServerTimer
:
public
TTimer
60
{
61
public
:
62
63
static
ServerTimer
*
fgTimer
;
64
65
static
void
StartServerTimer
(
int
period_msec = 100)
66
{
67
if
(!
fgTimer
)
68
{
69
fgTimer
=
new
ServerTimer
();
70
fgTimer
->Start(period_msec,kTRUE);
71
}
72
}
73
74
Bool_t
Notify
()
75
{
76
if
(
gDebugLockRoot
)
77
fprintf(stderr,
"ServerTimer::Notify!!\n"
);
78
79
int
notWaiting =
gWaitSema
.TryWait();
80
if
(
gDebugLockRoot
)
81
printf(
"NotWaiting %d!\n"
, notWaiting);
82
if
(!notWaiting)
83
{
84
if
(
gDebugLockRoot
)
85
printf(
"Yeld root sema!\n"
);
86
gRootSema
.Post();
87
TThread::Self()->Sleep(0, 1000000);
// sleep in ns
88
gDoneSema
.Wait();
89
if
(
gDebugLockRoot
)
90
printf(
"Recapture root sema!\n"
);
91
}
92
93
Reset();
94
return
kTRUE;
95
}
96
97
private
:
98
// ServerTimer is a singleton class,
99
// thus ctor and dtor are private
100
101
~ServerTimer
()
// dtor
102
{
103
//TurnOff();
104
}
105
106
ServerTimer
()
// ctor
107
{
108
//int period_msec = 100;
109
//Start(period_msec,kTRUE);
110
}
111
};
112
113
ServerTimer
*
ServerTimer::fgTimer
;
114
115
void
StartLockRootTimer
(
int
period_msec)
116
{
117
ServerTimer::StartServerTimer
(period_msec);
118
}
119
120
// end file
gDebugLockRoot
bool gDebugLockRoot
Definition
RootLock.cxx:22
LockRoot
void LockRoot()
Definition
RootLock.cxx:24
gRootSema
static TSemaphore gRootSema(0)
UnlockRoot
void UnlockRoot()
Definition
RootLock.cxx:34
gWaitSema
static TSemaphore gWaitSema(0)
StartLockRootTimer
void StartLockRootTimer(int period_msec)
Definition
RootLock.cxx:115
gDoneSema
static TSemaphore gDoneSema(0)
RootLock.h
LockRoot
void LockRoot()
Definition
RootLock.cxx:24
UnlockRoot
void UnlockRoot()
Definition
RootLock.cxx:34
ServerTimer
Definition
RootLock.cxx:60
ServerTimer::Notify
Bool_t Notify()
Definition
RootLock.cxx:74
ServerTimer::fgTimer
static ServerTimer * fgTimer
Definition
RootLock.cxx:63
ServerTimer::ServerTimer
ServerTimer()
Definition
RootLock.cxx:106
ServerTimer::~ServerTimer
~ServerTimer()
Definition
RootLock.cxx:101
ServerTimer::StartServerTimer
static void StartServerTimer(int period_msec=100)
Definition
RootLock.cxx:65
TTimer
LockRootGuard::~LockRootGuard
~LockRootGuard()
Definition
RootLock.cxx:47
LockRootGuard::Unlock
void Unlock()
Definition
RootLock.cxx:53
LockRootGuard::LockRootGuard
LockRootGuard()
Definition
RootLock.cxx:41
LockRootGuard::fLocked
bool fLocked
Definition
RootLock.h:19
Generated on Thu Dec 26 2024 05:01:02 for ROOTANA by
1.9.8