]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MONITOR/AliDimIntNotifier.cxx
Adding brand new 4 physics partition type - PHYSICS_X. Cross-checked and confirmed...
[u/mrichter/AliRoot.git] / MONITOR / AliDimIntNotifier.cxx
1 // @(#)root/eve:$Id$
2 // Author: Matevz Tadel 2007
3
4 /**************************************************************************
5  * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6  * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for          *
7  * full copyright notice.                                                 *
8  **************************************************************************/
9
10 #include "AliDimIntNotifier.h"
11
12 #include <signal.h>
13
14 //______________________________________________________________________________
15 // Full description of AliDimIntNotifier
16 //
17
18 ClassImp(AliDimIntNotifier)
19
20 Long_t AliDimIntNotifier::fgMainThreadId = 0;
21
22 void AliDimIntNotifier::SetMainThreadId()
23 {
24   fgMainThreadId = TThread::SelfId();
25 }
26
27 AliDimIntNotifier::AliDimIntNotifier(const TString& service) :
28   DimUpdatedInfo(service, -1),
29   fNotifyLck(kTRUE),
30   fNotifyCnd(&fNotifyLck),
31   fLastMessage(-1)
32 {
33   fReThreader.Connect("Timeout()", "AliDimIntNotifier", this, "DimMessage()");
34 }
35
36 void AliDimIntNotifier::StartTimer()
37 {
38   fReThreader.Reset();
39   fReThreader.TurnOn();
40   pthread_kill((pthread_t)fgMainThreadId, SIGALRM); 
41 }
42
43 void AliDimIntNotifier::StopTimer()
44 {
45   fReThreader.TurnOff();
46 }
47
48 void AliDimIntNotifier::infoHandler()
49 {
50   // Handle DIM message
51
52   fNotifyLck.Lock();
53   fLastMessage = getData() ? getInt() : -1;
54   if (TThread::SelfId() != fgMainThreadId)
55   {
56     StartTimer();
57     fNotifyCnd.Wait();
58   }
59   else
60   {
61     Warning("infoHandler", "DIM message received from CINT thread.");
62     DimMessage();
63   }
64   fNotifyLck.UnLock();
65 }
66
67 void AliDimIntNotifier::infoHandlerTest(Int_t fake)
68 {
69   // Fake handler for testing.
70
71   fNotifyLck.Lock();
72   fLastMessage = fake;
73   if (TThread::SelfId() != fgMainThreadId)
74   {
75     StartTimer();
76     fNotifyCnd.Wait();
77   }
78   else
79   {
80     Warning("infoHandlerTest", "Was called from CINT thread ...");
81     DimMessage();
82   }
83   fNotifyLck.UnLock();
84 }
85
86 void AliDimIntNotifier::DimMessage(Int_t)
87 {
88   StopTimer();
89   if (fLastMessage != -1)
90   {
91     Emit("DimMessage(Int_t)", fLastMessage);
92     printf("Notify %d\n", fLastMessage);
93   }
94   else
95   {
96     printf("NOTNotify %d\n", fLastMessage);
97   }
98   fNotifyLck.Lock();
99   fNotifyCnd.Signal();
100   fNotifyLck.UnLock();
101 }