]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MONITOR/AliDimIntNotifier.cxx
Some cleanup in the makefiles
[u/mrichter/AliRoot.git] / MONITOR / AliDimIntNotifier.cxx
CommitLineData
c6d78c69 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
ba04bf55 12#include <signal.h>
c6d78c69 13
14//______________________________________________________________________________
15// Full description of AliDimIntNotifier
16//
17
18ClassImp(AliDimIntNotifier)
19
20Long_t AliDimIntNotifier::fgMainThreadId = 0;
21
22void AliDimIntNotifier::SetMainThreadId()
23{
24 fgMainThreadId = TThread::SelfId();
25}
26
27AliDimIntNotifier::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
36void AliDimIntNotifier::StartTimer()
37{
38 fReThreader.Reset();
39 fReThreader.TurnOn();
49bacd14 40 pthread_kill((pthread_t)fgMainThreadId, SIGALRM);
c6d78c69 41}
42
43void AliDimIntNotifier::StopTimer()
44{
45 fReThreader.TurnOff();
46}
47
48void 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
67void 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
86void 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}