21#include "TGo4LockGuard.h"
27 GO4TRACE((15,
"TGo4ThreadHandler::TGo4ThreadHandler()",__LINE__, __FILE__));
36 :TNamed(name,
"This is a TGo4ThreadHandler"),
fbIsOperating(kFALSE)
38 GO4TRACE((15,
"TGo4ThreadHandler::TGo4ThreadHandler(const char *, TGo4ThreadManager *)",__LINE__, __FILE__));
49 GO4TRACE((15,
"TGo4ThreadHandler::~TGo4ThreadHandler()",__LINE__, __FILE__));
61 GO4TRACE((14,
"TGo4ThreadHandler::~TGo4ThreadHandler() Removing internal mode thread",__LINE__, __FILE__));
70 GO4TRACE((14,
"TGo4ThreadHandler::~TGo4ThreadHandler() Non internal mode thread",__LINE__, __FILE__));
84 GO4TRACE((14,
"TGo4ThreadHandler::AddThread(TGo4Thread *)", __LINE__, __FILE__));
89 if (!
fxArray->FindObject(gthr)) {
91 GO4TRACE((13,
"TGo4ThreadHandler::AddThread(TGo4Thread*) Adding new go4 thread to array", __LINE__, __FILE__));
96 GO4TRACE((13,
"TGo4ThreadHandler::AddThread(TGo4Thread*) Thread was already in array", __LINE__, __FILE__));
105 GO4TRACE((14,
"TGo4ThreadHandler::RemoveThread(const char *)",__LINE__, __FILE__));
109 TObject *obj =
fxArray->FindObject(name);
113 GO4TRACE((13,
"TGo4ThreadHandler::RemoveThread(const char *) Removing thread from array", __LINE__, __FILE__));
119 GO4TRACE((13,
"TGo4ThreadHandler::RemoveThread(const char *) Deleting internal mode thread", __LINE__, __FILE__));
128 GO4TRACE((13,
"TGo4ThreadHandler::RemoveThread(const char *) Non internal mode thread is not deleted", __LINE__, __FILE__));
132 GO4TRACE((13,
"TGo4ThreadHandler::RemoveThread(const char *) Thread not found in array", __LINE__, __FILE__));
141 GO4TRACE((14,
"TGo4ThreadHandler::NewThread(const char *,TGo4Runnable *)",__LINE__, __FILE__));
146 GO4TRACE((13,
"TGo4ThreadHandler::NewThread(const char *,TGo4Runnable *) No runnable specified error",__LINE__, __FILE__));
152 GO4TRACE((13,
"TGo4ThreadHandler::NewThread(const char *,TGo4Runnable *) Assigning external runnable to new internal thread",__LINE__, __FILE__));
161 GO4TRACE((15,
"TGo4ThreadHandler::CreateAll()",__LINE__, __FILE__));
162 Int_t createdthreads = 0;
174 GO4TRACE((13,
"TGo4ThreadHandler::CreateAll() Thread creation success",__LINE__, __FILE__));
179 GO4TRACE((13,
"TGo4ThreadHandler::CreateAll() Thread not created",__LINE__, __FILE__));
186 return createdthreads;
191 GO4TRACE((14,
"TGo4ThreadHandler::Create(const char *)",__LINE__, __FILE__));
197 GO4TRACE((13,
"TGo4ThreadHandler::Create(const char *) Creating new TThread for Go4Thread",__LINE__, __FILE__));
208 GO4TRACE((13,
"TGo4ThreadHandler::Create(const char *) Go4Thread was not found in thread array!",__LINE__, __FILE__));
216 GO4TRACE((15,
"TGo4ThreadHandler::CancelAll()",__LINE__, __FILE__));
217 Int_t cancelledthreads = 0;
226 GO4TRACE((13,
"TGo4ThreadHandler::CancelAll() Thread Cancel success", __LINE__, __FILE__));
230 GO4TRACE((13,
"TGo4ThreadHandler::CancelAll() Thread was not canceled", __LINE__, __FILE__));
235 return cancelledthreads;
240 GO4TRACE((14,
"TGo4ThreadHandler::Cancel(const char *)",__LINE__, __FILE__));
245 GO4TRACE((13,
"TGo4ThreadHandler::Cancel(const char *) Canceling TThread", __LINE__, __FILE__));
254 GO4TRACE((13,
"TGo4ThreadHandler::Cancel(const char *) Go4Thread was not found in thread array!", __LINE__, __FILE__));
262 GO4TRACE((15,
"TGo4ThreadHandler::ReCreateAll()",__LINE__, __FILE__));
263 Int_t recreatedthreads = 0;
274 GO4TRACE((13,
"TGo4ThreadHandler::ReCreateAll() Thread ReCreate success",__LINE__, __FILE__));
280 GO4TRACE((13,
"TGo4ThreadHandler::ReCreateAll() Thread was not recreated",__LINE__, __FILE__));
286 return recreatedthreads;
291 GO4TRACE((14,
"TGo4ThreadHandler::ReCreate(const char *)",__LINE__, __FILE__));
297 GO4TRACE((13,
"TGo4ThreadHandler::ReCreate(const char *) ReCreating TThread for Go4Thread",__LINE__, __FILE__));
308 GO4TRACE((13,
"TGo4ThreadHandler::ReCreate(const char *) Go4Thread was not found in thread array!",__LINE__, __FILE__));
317 GO4TRACE((15,
"TGo4ThreadHandler::StartAll()",__LINE__, __FILE__));
318 Int_t startedfuncs = 0;
332 GO4TRACE((13,
"TGo4ThreadHandler::StartAll() Thread Start success", __LINE__, __FILE__));
337 GO4TRACE((13,
"TGo4ThreadHandler::StartAll() Thread was already running", __LINE__, __FILE__));
348 GO4TRACE((14,
"TGo4ThreadHandler::Start(const char *)",__LINE__, __FILE__));
354 GO4TRACE((13,
"TGo4ThreadHandler::Start(const char *) Starting Thread",__LINE__, __FILE__));
365 GO4TRACE((13,
"TGo4ThreadHandler::Start(const char *) Go4Thread was not found in thread array!",__LINE__, __FILE__));
373 GO4TRACE((15,
"TGo4ThreadHandler::StopAll()",__LINE__, __FILE__));
374 Int_t stoppedfuncs = 0;
385 GO4TRACE((13,
"TGo4ThreadHandler::StopAll() Go4Thread Stop success",__LINE__, __FILE__));
392 GO4TRACE((13,
"TGo4ThreadHandler::StopAll() Go4Thread was already stopped",__LINE__, __FILE__));
401 GO4TRACE((14,
"TGo4ThreadHandler::Stop(const char *)",__LINE__, __FILE__));
407 GO4TRACE((13,
"TGo4ThreadHandler::Stop(const char *) Stopping Go4Runnable",__LINE__, __FILE__));
413 GO4TRACE((13,
"TGo4ThreadHandler::Stop(const char *) Go4Thread was not found in thread array!",__LINE__, __FILE__));
421 GO4TRACE((15,
"TGo4ThreadHandler::DumpThreads(Int_t)",__LINE__, __FILE__));
432 GO4TRACE((14,
"TGo4ThreadHandler::DumpThreads(Int_t) mode 0: File output",__LINE__, __FILE__));
433 strcpy(Filename,
"threaddump.txt");
434 fp = fopen(Filename,
"w");
437 GO4TRACE((13,
"TGo4ThreadHandler::DumpThreads(Int_t) fopen failed!!",__LINE__, __FILE__));
438 TGo4Log::Debug(
" ThreadHandler -- Error, Could not open thread dump file!");
444 GO4TRACE((13,
"TGo4ThreadHandler::DumpThreads(Int_t) writing into opened file",__LINE__, __FILE__));
445 fprintf(fp,
"\nTGo4ThreadHandler thread information dump file:\n");
451 fprintf(fp,
"TGo4Thread %d: \tPID:%d \tSelfID: %d",
453 fprintf(fp,
"\t name: %s\n",th->GetName());
458 GO4TRACE((13,
"TGo4ThreadHandler::DumpThreads(Int_t) fclose failed!!",__LINE__, __FILE__));
459 TGo4Log::Debug(
" ThreadHandlerr -- Error, Could not close thread dump file!");
467 GO4TRACE((14,
"TGo4ThreadHandler::DumpThreads(Int_t) mode: default ",__LINE__, __FILE__));
468 TGo4Log::Debug(
" ThreadHandlerr -- Error: DumpThreads mode unknown ");
477 GO4TRACE((12,
"TGo4ThreadHandler::GetThread(const char *)",__LINE__, __FILE__));
488 GO4TRACE((12,
"TGo4ThreadHandler::GetEntries()",__LINE__, __FILE__));
492 entries =
fxArray->GetEntries();
499 GO4TRACE((14,
"TGo4ThreadHandler::AllCreated()",__LINE__, __FILE__));
509 GO4TRACE((11,
"TGo4ThreadHandler::AllCreated() TThread is _not_ existing",__LINE__, __FILE__));
515 GO4TRACE((11,
"TGo4ThreadHandler::AllCreated() TThread is existing",__LINE__, __FILE__));
525 GO4TRACE((14,
"TGo4ThreadHandler::AllRunning()",__LINE__, __FILE__));
535 GO4TRACE((11,
"TGo4ThreadHandler::AllCreated() TGo4Thread is _not_ running",__LINE__, __FILE__));
541 GO4TRACE((11,
"TGo4ThreadHandler::AllCreated() TGo4Thread is running",__LINE__, __FILE__));
551 GO4TRACE((14,
"TGo4ThreadHandler::AllWaiting()",__LINE__, __FILE__));
559 GO4TRACE((11,
"TGo4ThreadHandler::AllCreated() TGo4Thread is still running",__LINE__, __FILE__));
563 GO4TRACE((11,
"TGo4ThreadHandler::AllCreated() TGo4Thread is waiting",__LINE__, __FILE__));
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
static Int_t GetIgnoreLevel()
Get threshold for output.
Base class for all go4 runnables.
TGo4Thread * GetThread(const char *name)
Access to Go4Thread by name.
Int_t DumpThreads(Int_t mode=0)
dumps thread process information to logging output i.e.
TMutex * fxListMutex
Mutex protecting thread array.
Bool_t AllCreated()
Returns true if all root threads in list are existing, i.e.
TGo4ThreadManager * fxManager
Backlink to threadmanager who owns this thread handler.
Int_t CancelAll()
Cancel all Threads in the thread list.
Int_t GetEntries() const
Number of threads in list.
Bool_t fbIsOperating
kTRUE, if threadhandler performs any action that requires gSystem support.
Bool_t RemoveThread(const char *name)
Remove thread by name from Thread List.
Int_t StopAll()
Start work function of all Threads in the thread list.
TIterator * fxIterator
Iterator for Thread Array.
Bool_t NewThread(const char *name, TGo4Runnable *runnable)
Creates new internal Go4 Thread with name and adds it to the List External runnable is passed to spec...
TGo4ThreadHandler(const TGo4ThreadHandler &right)
Bool_t AllWaiting()
Returns true if all threads in list are waiting, i.e.
Int_t ReCreateAll()
Recreate all Threads in the thread list.
Bool_t Start(const char *thname)
Starts work function of the Go4 Thread of name 'name'.
Int_t CreateAll()
Launch all Threads in the thread list.
Int_t StartAll()
Start work function of all Threads in the thread list.
TMutex * fxOperMutex
Mutex to protect IsOperating flag, flag is set kTRUE to indicate that AppControl timer must not block...
Bool_t AddThread(TGo4Thread *gthr)
Adds Reference to (externally created) thread to Thread List.
Bool_t AllRunning()
Returns true if all threads in list are running, i.e.
Bool_t Create(const char *thname)
Launch the ROOT Thread specified by the Go4 Thread of name 'name'.
Bool_t Stop(const char *thname)
Stops work function of the Go4 Thread of name 'name'.
TObjArray * fxArray
Array of Go4Threads.
Bool_t Cancel(const char *thname)
Cancels the ROOT Thread specified by the Go4 Thread of name 'name'.
Bool_t ReCreate(const char *thname)
ReCreate (Cancel and Create) all Threads in the thread list.
virtual ~TGo4ThreadHandler()
Bool_t Stop()
resets running flag for runnable
Bool_t IsWaiting() const
true if Threadfunc is suspended to condition wait
Long_t GetSelfID() const
self id of the current thread
Bool_t Cancel()
Cancels TThread.
Bool_t Create()
creates the TThread if not yet existing
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
Bool_t IsInternal() const
returns flag indicating if go4thread object is internal to threadhandler or created externally
Int_t GetPID() const
linux process id associated with the pthread
Bool_t IsRunning() const
Flag that controls Workfunc loop within Threadfunc.