GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
TGo4Thread Class Reference

go4 thread class More...

#include <TGo4Thread.h>

+ Inheritance diagram for TGo4Thread:

Public Member Functions

 TGo4Thread ()=delete
 
 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.
 
 TGo4Thread (const TGo4Thread &right)
 
virtual ~TGo4Thread ()
 
Bool_t Cancel ()
 Cancels TThread.
 
Bool_t Create ()
 creates the TThread if not yet existing
 
Int_t GetPID () const
 linux process id associated with the pthread
 
Long_t GetSelfID () const
 self id of the current thread
 
Bool_t IsCreated () const
 kTRUE if TThread instance exists and pthread is created
 
Bool_t IsInternal () const
 returns flag indicating if go4thread object is internal to threadhandler or created externally
 
Bool_t IsRunning () const
 Flag that controls Workfunc loop within Threadfunc.
 
Bool_t IsWaiting () const
 true if Threadfunc is suspended to condition wait
 
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
 

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

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

Static Private Member Functions

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

Private Attributes

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

Detailed Description

go4 thread class

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(at)gsi.de
Go4 project-DVEE-GSI Darmstadt
Germany
Version
0.9
Since
jul 2000-oct 2001

Definition at line 34 of file TGo4Thread.h.

Constructor & Destructor Documentation

◆ TGo4Thread() [1/3]

TGo4Thread::TGo4Thread ( )
delete

References TGo4Thread().

Referenced by TGo4Thread(), TGo4Thread(), and Threadfunc().

◆ TGo4Thread() [2/3]

TGo4Thread::TGo4Thread ( const TGo4Thread & right)

Definition at line 24 of file TGo4Thread.cxx.

References TGo4Thread(), fbIsInternal, fxCondition, fxRunnable, and GO4TRACE.

◆ TGo4Thread() [3/3]

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 33 of file TGo4Thread.cxx.

References TGo4Log::Debug(), fbIsCreated, fbIsInternal, fbIsRunning, fbIsWaiting, fiThreadPID, fiThreadSelfID, fxCondition, fxRunnable, fxThread, and GO4TRACE.

◆ ~TGo4Thread()

TGo4Thread::~TGo4Thread ( )
virtual

Definition at line 52 of file TGo4Thread.cxx.

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

Member Function Documentation

◆ Cancel()

◆ Create()

Bool_t TGo4Thread::Create ( )

creates the TThread if not yet existing

Definition at line 163 of file TGo4Thread.cxx.

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

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

◆ GetCondition()

TCondition * TGo4Thread::GetCondition ( ) const
inlineprivate

Definition at line 103 of file TGo4Thread.h.

References fxCondition.

Referenced by Threadfunc().

◆ GetPID()

Int_t TGo4Thread::GetPID ( ) const
inline

linux process id associated with the pthread

Definition at line 74 of file TGo4Thread.h.

References fiThreadPID.

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

◆ GetRunnable()

TGo4Runnable * TGo4Thread::GetRunnable ( ) const
inlineprivate

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

Definition at line 101 of file TGo4Thread.h.

References fxRunnable.

Referenced by Threadfunc().

◆ GetSelfID()

Long_t TGo4Thread::GetSelfID ( ) const
inline

self id of the current thread

Definition at line 77 of file TGo4Thread.h.

References fiThreadSelfID.

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

◆ IsCreated()

Bool_t TGo4Thread::IsCreated ( ) const
inline

kTRUE if TThread instance exists and pthread is created

Definition at line 84 of file TGo4Thread.h.

References fbIsCreated.

Referenced by Threadfunc().

◆ IsInternal()

Bool_t TGo4Thread::IsInternal ( ) const
inline

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

Definition at line 81 of file TGo4Thread.h.

References fbIsInternal.

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

◆ IsRunning()

Bool_t TGo4Thread::IsRunning ( ) const
inline

Flag that controls Workfunc loop within Threadfunc.

Definition at line 87 of file TGo4Thread.h.

References fbIsRunning.

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

◆ IsWaiting()

Bool_t TGo4Thread::IsWaiting ( ) const
inline

true if Threadfunc is suspended to condition wait

Definition at line 90 of file TGo4Thread.h.

References fbIsWaiting.

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

◆ ReCreate()

Bool_t TGo4Thread::ReCreate ( )

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

Definition at line 210 of file TGo4Thread.cxx.

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

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

◆ SetPID()

void TGo4Thread::SetPID ( )
private

Definition at line 302 of file TGo4Thread.cxx.

References fiThreadPID.

Referenced by Threadfunc().

◆ SetSelfID()

void TGo4Thread::SetSelfID ( )
private

Definition at line 297 of file TGo4Thread.cxx.

References fiThreadSelfID.

Referenced by Threadfunc().

◆ SetWaiting()

void TGo4Thread::SetWaiting ( Bool_t mode = kTRUE)
inlineprivate

Definition at line 109 of file TGo4Thread.h.

References fbIsWaiting.

Referenced by Threadfunc().

◆ Sleep()

◆ Start()

Bool_t TGo4Thread::Start ( )

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

Definition at line 264 of file TGo4Thread.cxx.

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

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

◆ Stop()

◆ Threadfunc()

void TGo4Thread::Threadfunc ( void * arg)
staticprivate

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 70 of file TGo4Thread.cxx.

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

Referenced by Create(), and ReCreate().

Field Documentation

◆ fbIsCreated

Bool_t TGo4Thread::fbIsCreated {kFALSE}
private

kTRUE if TThread instance exists and pthread is created

Definition at line 119 of file TGo4Thread.h.

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

◆ fbIsInternal

Bool_t TGo4Thread::fbIsInternal {kFALSE}
private

specifies whether thread is internal thread of handler (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 116 of file TGo4Thread.h.

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

◆ fbIsRunning

Bool_t TGo4Thread::fbIsRunning {kFALSE}
private

Flag that controls Workfunc loop within Threadfunc.

Definition at line 122 of file TGo4Thread.h.

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

◆ fbIsWaiting

Bool_t TGo4Thread::fbIsWaiting {kFALSE}
private

true if Threadfunc is suspended to condition wait

Definition at line 131 of file TGo4Thread.h.

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

◆ fiThreadPID

Int_t TGo4Thread::fiThreadPID {0}
private

Linux process id associated with the pthread.

Definition at line 125 of file TGo4Thread.h.

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

◆ fiThreadSelfID

Long_t TGo4Thread::fiThreadSelfID {0}
private

self id of the current thread

Definition at line 128 of file TGo4Thread.h.

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

◆ fxCondition

TCondition* TGo4Thread::fxCondition {nullptr}
private

Definition at line 144 of file TGo4Thread.h.

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

◆ fxRunnable

TGo4Runnable* TGo4Thread::fxRunnable {nullptr}
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 140 of file TGo4Thread.h.

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

◆ fxThread

TThread* TGo4Thread::fxThread {nullptr}
private

Definition at line 142 of file TGo4Thread.h.

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


The documentation for this class was generated from the following files: