GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4AppControlTimer.cxx
Go to the documentation of this file.
1// $Id$
2//-----------------------------------------------------------------------
3// The GSI Online Offline Object Oriented (Go4) Project
4// Experiment Data Processing at EE department, GSI
5//-----------------------------------------------------------------------
6// Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7// Planckstr. 1, 64291 Darmstadt, Germany
8// Contact: http://go4.gsi.de
9//-----------------------------------------------------------------------
10// This software can be used under the license agreements as stated
11// in Go4License.txt file which is part of the distribution.
12//-----------------------------------------------------------------------
13
14#include "TGo4AppControlTimer.h"
15
16#include "TCondition.h"
17#include "TApplication.h"
18#include "TThread.h"
19#include "TSystem.h"
20
21#include "TGo4Log.h"
22#include "TGo4ThreadManager.h"
23#include "TGo4ThreadHandler.h"
24
26
28
29TGo4AppControlTimer::TGo4AppControlTimer (TGo4ThreadManager *manager, Long_t msperiod, Bool_t mode)
30 :TTimer(msperiod,mode),
31 fxManager(manager),
32 fbApplicationRun(kFALSE)
33{
34 GO4TRACE((15,"TGo4AppControlTimer::TGo4AppControlTimer(TGo4ThreadManager *, Long_t, Bool_t) ctor",__LINE__, __FILE__));
35 fxCondition = new TCondition();
36}
37
38
40{
41 GO4TRACE((15,"TGo4AppControlTimer::~TGo4AppControlTimer() dtor",__LINE__, __FILE__));
42 if (fxCondition) {
43 delete fxCondition;
44 fxCondition = nullptr;
45 }
46}
47
49{
50 // TurnOff();
51 if(!fxManager)
52 {
53 TGo4Log::Error("TGo4AppControlTimer::Notify() NEVER COME HERE!!!");
54 TGo4Log::Error("TGo4AppControlTimer::Notify() with zero threadmanager!!!");
55 return kFALSE;
56
57 }
58 if(fxManager->Initialization() == 0)
59 // init successful?
60 {
61 GO4TRACE((11,"TGo4AppControlTimer: Successful Initialization",__LINE__, __FILE__));
63 // root TApplication shall be blocked
64 {
65 GO4TRACE((11,"TGo4AppControlTimer: Application shall be blocked!",__LINE__, __FILE__));
66 if(TThread::Exists())
67 // necessary to avoid gThreadImp bug in condition wait...
68 {
69 // normal mode:
70 GO4TRACE((10,"TGo4AppControlTimer: blocking ROOT gSystem!",__LINE__, __FILE__));
71 TGo4Log::Debug(" Application Control Timer -- Blocking ROOT gSystem!! ");
72 fxCondition->Wait(); // wait for running signal
73 TGo4Log::Debug(" Application Control Timer -- Releasing ROOT gSystem!! ");
74 }
75 else
76 {
77 // no thread up, cannot wait for condition
78 GO4TRACE((10,"TGo4AppControlTimer: no TThread existing, not blocking !",__LINE__, __FILE__));
79 }
80 }
81 else
82 {
83 // do not block :)
84 GO4TRACE((11,"TGo4AppControlTimer: Application shall not be blocked!",__LINE__, __FILE__));
85 }
86
87 if(fxManager->IsTerminating())
88 // check if Timer was woken for program end
89 {
90 GO4TRACE((11,"TGo4AppControlTimer: Terminating mode",__LINE__, __FILE__));
91 Int_t t = 0;
92 while(!(fxManager->GetWorkHandler()->AllWaiting()) && (t++ < fgiTERMWAITCYCLES)) {
93 TGo4Log::Debug(" Application Control Timer -- waiting for Runnables to stop... ");
94 gSystem->Sleep(fguTERMWAIT);
95 fxManager->GetWorkHandler()->StopAll();
96 }
97 TGo4Log::Debug(" Application Control Timer -- deleting TGo4ThreadManager! ");
98 Bool_t pleaseterminate=fxManager->IsTerminateApp();
99 delete fxManager; // executes dtors
100 fxManager = nullptr;
101 TurnOff(); // do not call this Notify again in Terminate
102 if(pleaseterminate)
103 {
104 TGo4Log::Debug(" Application Control Timer -- Terminating Application now! Goodbye...");
105 gApplication->Terminate(0);
106 }
107 else
108 {
109 TGo4Log::Debug(" Application Control Timer -- Finished Threadmanager deletion, killing myself now...");
110 delete this;
111 }
112 return kFALSE;
113 } // if(pleaseterminate)
114 else
115 {
116 // prepare for another timer cycle
117 GO4TRACE((11,"TGo4AppControlTimer: Resetting for new cycle",__LINE__, __FILE__));
118 Reset();
119 // TurnOn();
120 }
121 } //if(fxManager->Initialization() == 0)
122 else
123 // init not successful
124 {
125 GO4TRACE((11,"TGo4AppControlTimer: Initialization failed",__LINE__, __FILE__));
126 TGo4Log::Debug(" Application Control Timer -- ThreadManager Init not successful, retrying! ");
127 Reset();
128// TurnOn();
129 }
130 return kFALSE;
131}
#define GO4TRACE(X)
Definition TGo4Log.h:25
Bool_t Notify() override
Routine called from TTimer on timeout.
TGo4ThreadManager * fxManager
Backlink to threadmanager who owns this timer.
static UInt_t fguTERMWAIT
time in ms to wait for all Runnables being stopped before Termination; after this time,...
TGo4AppControlTimer()=delete
static Int_t fgiTERMWAITCYCLES
On Termination, Notify will test fgiTERMWAITCYCLES times if Runnables are stopped,...
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Definition TGo4Log.cxx:281
static void Error(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 3.
Definition TGo4Log.cxx:320
Go4 thread manager.