ROOTANA
Loading...
Searching...
No Matches
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
18static TSemaphore gRootSema(0); // wait by server, post by timer
19static TSemaphore gWaitSema(0); // post by server, wait by timer
20static TSemaphore gDoneSema(0); // post by server, wait by timer
21
22bool gDebugLockRoot = false;
23
25{
27 printf("Try Lock ROOT!\n");
28 gWaitSema.Post();
29 gRootSema.Wait();
31 printf("Lock ROOT!\n");
32}
33
35{
37 printf("Unlock ROOT!\n");
38 gDoneSema.Post();
39}
40
42{
43 fLocked = true;
44 LockRoot();
45}
46
48{
49 if (fLocked)
50 Unlock();
51}
52
54{
55 UnlockRoot();
56 fLocked = false;
57}
58
59class ServerTimer : public TTimer
60{
61public:
62
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 {
77 fprintf(stderr, "ServerTimer::Notify!!\n");
78
79 int notWaiting = gWaitSema.TryWait();
81 printf("NotWaiting %d!\n", notWaiting);
82 if (!notWaiting)
83 {
85 printf("Yeld root sema!\n");
86 gRootSema.Post();
87 TThread::Self()->Sleep(0, 1000000); // sleep in ns
88 gDoneSema.Wait();
90 printf("Recapture root sema!\n");
91 }
92
93 Reset();
94 return kTRUE;
95 }
96
97private:
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
114
115void StartLockRootTimer(int period_msec)
116{
118}
119
120// end file
bool gDebugLockRoot
Definition RootLock.cxx:22
void LockRoot()
Definition RootLock.cxx:24
static TSemaphore gRootSema(0)
void UnlockRoot()
Definition RootLock.cxx:34
static TSemaphore gWaitSema(0)
void StartLockRootTimer(int period_msec)
Definition RootLock.cxx:115
static TSemaphore gDoneSema(0)
void LockRoot()
Definition RootLock.cxx:24
void UnlockRoot()
Definition RootLock.cxx:34
Bool_t Notify()
Definition RootLock.cxx:74
static ServerTimer * fgTimer
Definition RootLock.cxx:63
static void StartServerTimer(int period_msec=100)
Definition RootLock.cxx:65
void Unlock()
Definition RootLock.cxx:53