Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4Thread Class Reference

Class that encapsulates a root TThread which calls a user runnable Method (TGo4Runnable::Run()) in a loop. More...

#include <TGo4Thread.h>

List of all members.

Public Member Functions

 TGo4Thread (const TGo4Thread &right)
 TGo4Thread (const char *name, TGo4Runnable *runnable, Bool_t internal=kTRUE)
 TGo4Thread constructor parameters: name: name of the thread runnable: external user runnable to be executed from TThread.
virtual ~TGo4Thread ()
Bool_t Create ()
 creates the TThread if not yet existing
Bool_t Cancel ()
 Cancels TThread.
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 Stop ()
 resets running flag for runnable
Int_t GetPID () const
 linux process id associated with the pthread
Long_t GetSelfID () const
 self id of the current thread
Bool_t IsInternal () const
 returns flag indicating if go4thread object is internal to threadhandler or created externally
Bool_t IsCreated () const
 kTRUE if TThread instance exists and pthread is created
Bool_t IsRunning () const
 Flag that controls Workfunc loop within Threadfunc.
Bool_t IsWaiting () const
 true if Threadfunc is suspended to condition wait

Static Public Member Functions

static void Sleep (UInt_t millisecs)
 wrapper for gSystem->Sleep with consecutive TThread::CancelPoint - necessary for proper pthread termination

Private Member Functions

TGo4RunnableGetRunnable () const
 We need this to have access to instance runnable from static Threadfunc:.
TCondition * GetCondition () const
void SetPID ()
void SetSelfID ()
void SetWaiting (Bool_t mode=kTRUE)
 TGo4Thread ()

Static Private Member Functions

static void Threadfunc (void *arg)
 This function is passed to TThread ctor and runs as pthread.

Private Attributes

Bool_t fbIsInternal
 specifes whether thread is internal thread of handlerr (true) or is owned by external class (false).
Bool_t fbIsCreated
 kTRUE if TThread instance exists and pthread is created
Bool_t fbIsRunning
 Flag that controls Workfunc loop within Threadfunc.
Int_t fiThreadPID
 Linux process id associated with the pthread.
Long_t fiThreadSelfID
 self id of the current thread
Bool_t fbIsWaiting
 true if Threadfunc is suspended to condition wait
TGo4RunnablefxRunnable
 External class providing the threaded workfunction and exception routines for workfunction.
TThread * fxThread
TCondition * fxCondition


Detailed Description

Class that encapsulates a root TThread which calls a user runnable Method (TGo4Runnable::Run()) in a loop.

This working loop can be suspended to a condition wait to stop the action.

Author:
J. Adamczewski

Go4 project-DVEE-GSI Darmstadt

Germany

j.adamczewski@gsi.de

Version:
0.9
Since:
jul 2000-oct 2001

Definition at line 35 of file TGo4Thread.h.


Constructor & Destructor Documentation

TGo4Thread::TGo4Thread const TGo4Thread right  ) 
 

Definition at line 29 of file TGo4Thread.cxx.

References fbIsInternal, fxCondition, fxRunnable, and TRACE.

TGo4Thread::TGo4Thread const char *  name,
TGo4Runnable runnable,
Bool_t  internal = kTRUE
 

TGo4Thread constructor parameters: name: name of the thread runnable: external user runnable to be executed from TThread.

internal: define if thread shall be owned by threadmanager, or if it belongs to other aggregation

Definition at line 38 of file TGo4Thread.cxx.

References TGo4Log::Debug(), fbIsInternal, fxCondition, fxRunnable, TGo4Runnable::SetThread(), and TRACE.

TGo4Thread::~TGo4Thread  )  [virtual]
 

Definition at line 57 of file TGo4Thread.cxx.

References Cancel(), TGo4Log::Debug(), fbIsInternal, fxCondition, fxRunnable, Stop(), and TRACE.

TGo4Thread::TGo4Thread  )  [private]
 


Member Function Documentation

Bool_t TGo4Thread::Create  ) 
 

creates the TThread if not yet existing

Definition at line 171 of file TGo4Thread.cxx.

References fbIsCreated, fxThread, Threadfunc(), and TRACE.

Referenced by TGo4ThreadHandler::Create(), TGo4ThreadHandler::CreateAll(), ReCreate(), and Start().

Bool_t TGo4Thread::Cancel  ) 
 

Cancels TThread.

Definition at line 191 of file TGo4Thread.cxx.

References TGo4Log::Debug(), fbIsCreated, fbIsRunning, fiThreadPID, fiThreadSelfID, fxCondition, fxThread, Sleep(), and TRACE.

Referenced by TGo4ThreadHandler::Cancel(), TGo4ThreadHandler::CancelAll(), TGo4TestRunnable::Run(), and ~TGo4Thread().

Bool_t TGo4Thread::ReCreate  ) 
 

Stops old Runnable; Creates new TThread of same Runnable and name; cancels old Thread.

Definition at line 248 of file TGo4Thread.cxx.

References Create(), TGo4Log::Debug(), fbIsCreated, fbIsWaiting, fiThreadPID, fiThreadSelfID, fxCondition, fxThread, Start(), Stop(), Threadfunc(), and TRACE.

Referenced by TGo4ThreadHandler::ReCreate(), and TGo4ThreadHandler::ReCreateAll().

Bool_t TGo4Thread::Start  ) 
 

starts runnable method Run within thread loop by setting running flag and signaling condition

Definition at line 304 of file TGo4Thread.cxx.

References Create(), fbIsCreated, fbIsRunning, fxCondition, and TRACE.

Referenced by ReCreate(), TGo4ThreadHandler::Start(), and TGo4ThreadHandler::StartAll().

Bool_t TGo4Thread::Stop  ) 
 

resets running flag for runnable

Definition at line 325 of file TGo4Thread.cxx.

References fbIsRunning, and TRACE.

Referenced by ReCreate(), TGo4ConnectorRunnable::Run(), TGo4ObjConnectorRunnable::Run(), TGo4ThreadHandler::Stop(), TGo4ThreadHandler::StopAll(), and ~TGo4Thread().

void TGo4Thread::Sleep UInt_t  millisecs  )  [static]
 

wrapper for gSystem->Sleep with consecutive TThread::CancelPoint - necessary for proper pthread termination

Definition at line 333 of file TGo4Thread.cxx.

References TRACE.

Referenced by Cancel(), TGo4TaskHandlerRunnable::CheckTransportOpen(), TGo4HistogramServer::ConnectObjectClient(), TGo4ComInitAnalysis::ExeCom(), TGo4TestRunnable::Run(), TGo4WatchRunnable::Run(), TGo4MainRunnable::Run(), TGo4LoggingRunnable::Run(), TGo4ControllerRunnable::Run(), TGo4AnalysisWatchRunnable::Run(), TGo4AnalysisMainRunnable::Run(), TGo4TaskManager::ServeClient(), TGo4ServerTask::Shutdown(), Threadfunc(), TGo4TaskManager::WaitForClientRemoved(), TGo4ServerTask::WaitForClose(), TGo4HistogramServer::WaitForClose(), TGo4ServerTask::WaitForConnection(), TGo4HistogramServer::WaitForConnection(), TGo4ServerTask::WaitForOpen(), TGo4HistogramServer::WaitForOpen(), TGo4TaskHandler::WaitGetPort(), and TGo4TaskHandler::WaitThreadStop().

Int_t TGo4Thread::GetPID  )  const [inline]
 

linux process id associated with the pthread

Definition at line 73 of file TGo4Thread.h.

References fiThreadPID.

Referenced by TGo4ThreadHandler::AllCreated(), TGo4ThreadHandler::DumpThreads(), TGo4Runnable::ThreadCatch(), Threadfunc(), and TGo4Runnable::UnexpectedCatch().

Long_t TGo4Thread::GetSelfID  )  const [inline]
 

self id of the current thread

Definition at line 76 of file TGo4Thread.h.

References fiThreadSelfID.

Referenced by TGo4ThreadHandler::DumpThreads(), and Threadfunc().

Bool_t TGo4Thread::IsInternal  )  const [inline]
 

returns flag indicating if go4thread object is internal to threadhandler or created externally

Definition at line 80 of file TGo4Thread.h.

References fbIsInternal.

Referenced by TGo4ThreadHandler::RemoveThread(), and TGo4ThreadHandler::~TGo4ThreadHandler().

Bool_t TGo4Thread::IsCreated  )  const [inline]
 

kTRUE if TThread instance exists and pthread is created

Definition at line 83 of file TGo4Thread.h.

References fbIsCreated.

Referenced by Threadfunc().

Bool_t TGo4Thread::IsRunning  )  const [inline]
 

Flag that controls Workfunc loop within Threadfunc.

Definition at line 86 of file TGo4Thread.h.

References fbIsRunning.

Referenced by TGo4ThreadHandler::AllRunning(), and Threadfunc().

Bool_t TGo4Thread::IsWaiting  )  const [inline]
 

true if Threadfunc is suspended to condition wait

Definition at line 89 of file TGo4Thread.h.

References fbIsWaiting.

Referenced by TGo4ThreadHandler::AllWaiting(), TGo4ServerTask::ConnectorThreadIsStopped(), and TGo4TaskHandler::WaitThreadStop().

void TGo4Thread::Threadfunc void *  arg  )  [static, private]
 

This function is passed to TThread ctor and runs as pthread.

Contains a loop that is controlled by Go4Thread own TCondition and by "function shall run" flag. Within the loop the virtual working function is called.

Definition at line 79 of file TGo4Thread.cxx.

References TGo4Log::Debug(), GetCondition(), GetPID(), GetRunnable(), GetSelfID(), IsCreated(), IsRunning(), TGo4Runnable::PostRun(), TGo4Runnable::PreRun(), TGo4Runnable::Run(), SetPID(), SetSelfID(), SetWaiting(), Sleep(), TGo4Runnable::ThreadCatch(), and TRACE.

Referenced by Create(), and ReCreate().

TGo4Runnable* TGo4Thread::GetRunnable  )  const [inline, private]
 

We need this to have access to instance runnable from static Threadfunc:.

Definition at line 100 of file TGo4Thread.h.

References fxRunnable.

Referenced by Threadfunc().

TCondition* TGo4Thread::GetCondition  )  const [inline, private]
 

Definition at line 102 of file TGo4Thread.h.

References fxCondition.

Referenced by Threadfunc().

void TGo4Thread::SetPID  )  [private]
 

Definition at line 345 of file TGo4Thread.cxx.

References fiThreadPID.

Referenced by Threadfunc().

void TGo4Thread::SetSelfID  )  [private]
 

Definition at line 340 of file TGo4Thread.cxx.

References fiThreadSelfID.

Referenced by Threadfunc().

void TGo4Thread::SetWaiting Bool_t  mode = kTRUE  )  [inline, private]
 

Definition at line 108 of file TGo4Thread.h.

References fbIsWaiting.

Referenced by Threadfunc().


Member Data Documentation

Bool_t TGo4Thread::fbIsInternal [private]
 

specifes whether thread is internal thread of handlerr (true) or is owned by external class (false).

In the latter case, thread instance and its runnable are not deleted when it is removed from the thread list

Definition at line 115 of file TGo4Thread.h.

Referenced by IsInternal(), TGo4Thread(), and ~TGo4Thread().

Bool_t TGo4Thread::fbIsCreated [private]
 

kTRUE if TThread instance exists and pthread is created

Definition at line 118 of file TGo4Thread.h.

Referenced by Cancel(), Create(), IsCreated(), ReCreate(), and Start().

Bool_t TGo4Thread::fbIsRunning [private]
 

Flag that controls Workfunc loop within Threadfunc.

Definition at line 121 of file TGo4Thread.h.

Referenced by Cancel(), IsRunning(), Start(), and Stop().

Int_t TGo4Thread::fiThreadPID [private]
 

Linux process id associated with the pthread.

Definition at line 124 of file TGo4Thread.h.

Referenced by Cancel(), GetPID(), ReCreate(), and SetPID().

Long_t TGo4Thread::fiThreadSelfID [private]
 

self id of the current thread

Definition at line 127 of file TGo4Thread.h.

Referenced by Cancel(), GetSelfID(), ReCreate(), and SetSelfID().

Bool_t TGo4Thread::fbIsWaiting [private]
 

true if Threadfunc is suspended to condition wait

Definition at line 130 of file TGo4Thread.h.

Referenced by IsWaiting(), ReCreate(), and SetWaiting().

TGo4Runnable* TGo4Thread::fxRunnable [private]
 

External class providing the threaded workfunction and exception routines for workfunction.

The threaded action will be defined by creating a runnable subclass and overriding the TGo4Runnable::Run() method. Here exception handling behaviour may be overridden, too. 1 1

Definition at line 139 of file TGo4Thread.h.

Referenced by GetRunnable(), TGo4Thread(), and ~TGo4Thread().

TThread* TGo4Thread::fxThread [private]
 

Definition at line 141 of file TGo4Thread.h.

Referenced by Cancel(), Create(), and ReCreate().

TCondition* TGo4Thread::fxCondition [private]
 

Definition at line 143 of file TGo4Thread.h.

Referenced by Cancel(), GetCondition(), ReCreate(), Start(), TGo4Thread(), and ~TGo4Thread().


The documentation for this class was generated from the following files:
Generated on Fri Nov 28 13:01:21 2008 for Go4-v3.04-1 by  doxygen 1.4.2