ZeusBase-Library  2.0.4
zeus::TThread Class Reference

#include <Thread.h>

Inheritance diagram for zeus::TThread:
zeus::TZObject zeus::IThread zeus::IZUnknown zeus::IZUnknown zeus::TAbstractSkel zeus::TAbstractSkel::TClientHandlerThread zeus::TPeerFinder zeus::TPeerProvider zeus::TCommPipe_Skel zeus::TMessagePool_Skel zeus::TMessageServerConnection_Skel zeus::TNamedContext_Skel

Public Types

enum  EPriority {
  etNormal = 0, etLow = 1, etHigh = 2, etLower = 3,
  etHigher = 4, etTimeCritical = 5
}
 

Public Member Functions

 TThread (EPriority ePriority=etNormal)
 
 TThread (IRunnable &rObj, EPriority ePriority=etNormal)
 
EPriority getPriority () const
 
void setPriority (EPriority ePriority)
 
virtual void kill (Float64 dTimeOut=0)
 
virtual bool isAlive () const
 
virtual bool isDead () const
 
virtual void resume ()
 
virtual bool signalizeStop (Float64 dTimeOut=5.0)
 
virtual bool start ()
 
virtual void suspend ()
 
virtual bool yield ()
 
virtual Retval postObject (ISynchronizeObject &rObject, bool bWaitForCompletion)
 
virtual bool MQUALIFIER isInterrupted () const
 
virtual Uint MQUALIFIER getThreadID () const
 
virtual Retval MQUALIFIER askForInterface (const InterfaceID &rInterfaceID, IZUnknown *&rpIface)
 
virtual void MQUALIFIER addRef () const
 
virtual void MQUALIFIER release () const
 
- Public Member Functions inherited from zeus::TZObject
 TZObject ()
 
 TZObject (const TString &strName)
 
 TZObject (const IString &strName)
 
Uint getHash () const
 
TString toString () const
 
virtual TString getObjName () const
 
virtual void setObjName (const TString &name)
 

Static Public Member Functions

static void sleep (const Float &rfDelay)
 

Protected Member Functions

virtual ~TThread ()
 
virtual void execute ()
 
virtual void onTerminated ()
 
virtual void onStarted ()
 
- Protected Member Functions inherited from zeus::TZObject
virtual ~TZObject ()
 
 TZObject (const TZObject &rObject)
 
TZObjectoperator= (const TZObject &rObject)
 
Int getRefCounter () const
 

Protected Attributes

bool m_bInterrupted
 Flag to check if the thread should terminate. More...
 
TThreadMessageQueuem_rQueue
 Message queue of the thread. More...
 
- Protected Attributes inherited from zeus::TZObject
Uint m_uiID
 

Detailed Description

This class wrapps a kernel thread object. It provides a simple and convinient interface to the API functions using object oriented design. Lots of tricky code is wrapped to avoid deadlocks and other nasty behaviours just using API functions.

Member Enumeration Documentation

§ EPriority

Type of thread priority

Enumerator
etNormal 
etLow 
etHigh 
etLower 
etHigher 
etTimeCritical 

Constructor & Destructor Documentation

§ TThread() [1/2]

TThread::TThread ( EPriority  ePriority = etNormal)

Creates a thread

Parameters
ePriority: Thread priority

§ TThread() [2/2]

TThread::TThread ( IRunnable rObj,
EPriority  ePriority = etNormal 
)

Creates a thread using an external object as executing

Parameters
rObj: Object for execution
ePriority: Thread priority

§ ~TThread()

TThread::~TThread ( )
protectedvirtual

Destroys the thread

Member Function Documentation

§ addRef()

virtual void MQUALIFIER zeus::TThread::addRef ( ) const
virtual
See also
IZUnknown::addRef

Reimplemented from zeus::TZObject.

Reimplemented in zeus::TPeerFinder.

§ askForInterface()

virtual Retval MQUALIFIER zeus::TThread::askForInterface ( const InterfaceID rInterfaceID,
IZUnknown *&  rpIface 
)
virtual
See also
IZUnknown::askForInterface

Reimplemented from zeus::TZObject.

Reimplemented in zeus::TPeerFinder.

§ execute()

void TThread::execute ( )
protectedvirtual

This is the internal running method. Do not call this method directly

Reimplemented in zeus::TAbstractSkel::TClientHandlerThread, zeus::TAbstractSkel, zeus::TPeerFinder, and zeus::TPeerProvider.

§ getPriority()

TThread::EPriority zeus::TThread::getPriority ( ) const
inline

returns the priority of the thread

§ getThreadID()

Uint MQUALIFIER TThread::getThreadID ( ) const
virtual
See also
IThread::getThreadID

Implements zeus::IThread.

§ isAlive()

bool zeus::TThread::isAlive ( ) const
inlinevirtual

Inverse of isDead

§ isDead()

bool zeus::TThread::isDead ( ) const
inlinevirtual

Checks if the thread is dead. The thread is dead if never start() has been called or after its termination using signalizeStop() or kill().

Return values
true: Thread is not running
false: Thread still runs

§ isInterrupted()

bool MQUALIFIER zeus::TThread::isInterrupted ( ) const
inlinevirtual

§ kill()

void TThread::kill ( Float64  dTimeOut = 0)
virtual

Terminates the thread. If time out is not zero, this method will wait, until the thread terminats itself. If timeout occures, the thread will be forced to terminate. This might cause ressource leaks.

Parameters
dTimeOut: Time out

Reimplemented in zeus::TAbstractSkel::TClientHandlerThread, and zeus::TAbstractSkel.

§ onStarted()

virtual void zeus::TThread::onStarted ( )
inlineprotectedvirtual

§ onTerminated()

virtual void zeus::TThread::onTerminated ( )
inlineprotectedvirtual

§ postObject()

Retval TThread::postObject ( ISynchronizeObject rObject,
bool  bWaitForCompletion 
)
virtual

this sends a message to the queue of the thread

Note
This method could cause dead locks, if the thread is not started, but the bWaitForCompletion flag is set. Start the thread first
See also
IThreadManager::postObject

§ release()

virtual void MQUALIFIER zeus::TThread::release ( ) const
virtual
See also
IZUnknown::release

Reimplemented from zeus::TZObject.

Reimplemented in zeus::TPeerFinder.

§ resume()

void TThread::resume ( )
virtual

This starts a stopped thread.

§ setPriority()

void TThread::setPriority ( EPriority  ePriority)

sets a new priority of the thread

Parameters
ePriority: new priority

§ signalizeStop()

bool TThread::signalizeStop ( Float64  dTimeOut = 5.0)
virtual

Sets the interrupped signal.

Note
the minimal time slice is about 0.1 sec.

Reimplemented in zeus::TPeerFinder, and zeus::TPeerProvider.

§ sleep()

void TThread::sleep ( const Float &  rfDelay)
static

Suspends the thread for a given time in seconds

§ start()

bool TThread::start ( )
virtual

Starts the thread.

Return values
trueThread created and successfully started
falseCould not start the thread (OS error)

§ suspend()

void TThread::suspend ( )
virtual

This stopps a thread. Using resume() the thread can be restarted

§ yield()

bool TThread::yield ( )
virtual

this method causes the OS to switch to an other thread (scheduling).

Return values
true: yield has been performed
falsecould not yield thread

Member Data Documentation

§ m_bInterrupted

bool zeus::TThread::m_bInterrupted
protected

Flag to check if the thread should terminate.

§ m_rQueue

TThreadMessageQueue& zeus::TThread::m_rQueue
protected

Message queue of the thread.


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


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Tue Sep 13 2016 22:32:14