18#include "TCondition.h"
27 GO4TRACE((14,
"TGo4Thread::TGo4Thread(const TGo4Thread &)",__LINE__, __FILE__));
34 :TNamed(name,
"This is a TGo4Thread"),
42 GO4TRACE((14,
"TGo4Thread::TGo4Thread(const char *, TGo4Runnable *, Bool_t)",__LINE__, __FILE__));
54 GO4TRACE((14,
"TGo4Thread::~TGo4Thread()",__LINE__, __FILE__));
61 GO4TRACE((14,
"TGo4Thread::~TGo4Thread() internal mode", __LINE__, __FILE__));
65 GO4TRACE((14,
"TGo4Thread::~TGo4Thread() non internal mode", __LINE__, __FILE__));
72 GO4TRACE((2,
"TGo4Thread::Threadfunc(void *)",__LINE__, __FILE__));
82 TGo4Log::Debug(
" TThread %ld (PID:%d) of Go4Thread ``%s'' started... \n",
89 GO4TRACE((1,
"TGo4Thread::Threadfunc(void *) try block",__LINE__, __FILE__));
92 TThread::CancelPoint();
95 GO4TRACE((1,
"TGo4Thread::Threadfunc(void *) waiting mode",__LINE__, __FILE__));
97 go4th->GetName(), go4th->
GetPID());
102 go4th->GetName(), go4th->
GetPID() );
112 GO4TRACE((1,
"TGo4Thread::Threadfunc(void *) entering running mode",__LINE__, __FILE__));
114 runnable->
PreRun((
void *) 0);
117 TThread::CancelPoint();
118 runnable->
Run((
void *) 0);
127 GO4TRACE((1,
"TGo4Thread::Threadfunc(void *) entering Cancel loop",__LINE__, __FILE__));
128 TGo4Log::Debug(
" Go4Thread ``%s'' entering Cancel loop\n ", go4th->GetName());
135 GO4TRACE((1,
"TGo4Thread::Threadfunc(void *) in Cancel loop",__LINE__, __FILE__));
137 TThread::CancelPoint();
146 GO4TRACE((1,
"TGo4Thread::Threadfunc(void *) Go4Exception Catch",__LINE__, __FILE__));
148 TThread::CancelPoint();
153 GO4TRACE((1,
"TGo4Thread::Threadfunc(void *) Unexpected Catch",__LINE__, __FILE__));
155 TThread::CancelPoint();
165 GO4TRACE((14,
"TGo4Thread::Create()",__LINE__, __FILE__));
180 GO4TRACE((14,
"TGo4Thread::Cancel()",__LINE__, __FILE__));
184 TGo4Log::Debug(
" Go4Thread ``%s'' -- Canceling TThread %ld (PID:%d) ",
187 GO4TRACE((13,
"TGo4Thread::Cancel() -- canceling existing TThread",__LINE__, __FILE__));
200 GO4TRACE((13,
"TGo4Thread::Cancel() -- Error: TThread pointer is zero!",__LINE__, __FILE__));
201 TGo4Log::Debug(
" Go4Thread ``%s'' Cancel -- Internal inconsistency error! ",GetName());
212 GO4TRACE((14,
"TGo4Thread::ReCreate()",__LINE__, __FILE__));
219 GO4TRACE((13,
"TGo4Thread::ReCreate() -- old TThread existing",__LINE__, __FILE__));
220 TGo4Log::Debug(
" Recreating Go4Thread ``%s'' -- old TThread %ld (PID:%d) ",
224 GO4TRACE((13,
"TGo4Thread::ReCreate() -- recreating existing TThread",__LINE__, __FILE__));
240 TThread::Delete(oldthread);
249 GO4TRACE((13,
"TGo4Thread::ReCreate() -- Error: old TThread pointer is zero!",__LINE__, __FILE__));
250 TGo4Log::Debug(
" Go4Thread ``%s'' ReCreate -- Internal inconsistency error! ",GetName());
258 GO4TRACE((13,
"TGo4Thread::ReCreate() -- old TThread existing",__LINE__, __FILE__));
266 GO4TRACE((12,
"TGo4Thread::Start()",__LINE__, __FILE__));
270 GO4TRACE((11,
"TGo4Thread::Start() -- creating new TThread",__LINE__, __FILE__));
274 GO4TRACE((11,
"TGo4Thread::Start() -- TThread already existing",__LINE__, __FILE__));
284 GO4TRACE((12,
"TGo4Thread::Stop()",__LINE__, __FILE__));
292 GO4TRACE((12,
"TGo4Thread::Sleep()",__LINE__, __FILE__));
293 gSystem->Sleep(millisecs);
294 TThread::CancelPoint();
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
Base class for all go4 runnables.
virtual void ThreadCatch(TGo4Exception &ex)
catch for exceptions occurring in workfunc
virtual Int_t PostRun(void *ptr)
Function which is called once after the Run()method on threadstop.
virtual Int_t Run(void *ptr)=0
The working function which runs in the thread.
virtual Int_t PreRun(void *ptr)
Function which is called once before the Run() method on threadstart.
Bool_t Stop()
resets running flag for runnable
Int_t fiThreadPID
Linux process id associated with the pthread.
Bool_t fbIsCreated
kTRUE if TThread instance exists and pthread is created
void SetWaiting(Bool_t mode=kTRUE)
Bool_t fbIsWaiting
true if Threadfunc is suspended to condition wait
Long_t GetSelfID() const
self id of the current thread
Bool_t IsCreated() const
kTRUE if TThread instance exists and pthread is created
Long_t fiThreadSelfID
self id of the current thread
Bool_t Cancel()
Cancels TThread.
TGo4Runnable * fxRunnable
External class providing the threaded workfunction and exception routines for workfunction.
Bool_t fbIsRunning
Flag that controls Workfunc loop within Threadfunc.
Bool_t Create()
creates the TThread if not yet existing
Bool_t fbIsInternal
specifies whether thread is internal thread of handler (true) or is owned by external class (false).
TGo4Runnable * GetRunnable() const
We need this to have access to instance runnable from static Threadfunc:
static void Sleep(UInt_t millisecs)
wrapper for gSystem->Sleep with consecutive TThread::CancelPoint - necessary for proper pthread termi...
Bool_t ReCreate()
Stops old Runnable; Creates new TThread of same Runnable and name; cancels old Thread.
Bool_t Start()
starts runnable method Run within thread loop by setting running flag and signaling condition
Int_t GetPID() const
linux process id associated with the pthread
static void Threadfunc(void *arg)
This function is passed to TThread ctor and runs as pthread.
TCondition * GetCondition() const
Bool_t IsRunning() const
Flag that controls Workfunc loop within Threadfunc.