OSB_APP::ThreadBase Class Reference

Collaboration diagram for OSB_APP::ThreadBase:

Collaboration graph
[legend]
List of all members.

Detailed Description

Wrapper around a POSIX thread.

Definition at line 73 of file osbthread.h.

Public Member Functions

Public Attributes

Protected Member Functions

Protected Attributes

Private Member Functions

Private Attributes

Friends


Constructor & Destructor Documentation

OSB_APP::ThreadBase::ThreadBase ( int  id = 0  ) 

Default constructor with optional user defined id.

virtual OSB_APP::ThreadBase::~ThreadBase (  )  [virtual]

Virtual destructor.


Member Function Documentation

void OSB_APP::ThreadBase::hasReturned (  )  [private]

Set running_ to false.

virtual int OSB_APP::ThreadBase::join ( bool  doStop,
int  signum = 0 
) [virtual]

Join the thread, possibly stopping it.

Parameters:
doStop Flag to stop the thread.
signum Signal number to send, see below.
Returns:
The return value of the thread: rc().
The function returns if thread is not running().

If doStop is true the function

Afterwards pthread_join() is called.

int OSB_APP::ThreadBase::lock (  )  const [protected]

Lock the mutex.

void OSB_APP::ThreadBase::rc ( int  ret  )  [protected]

Set the return value.

int OSB_APP::ThreadBase::rc (  )  const

Return value of the thread.

Returns:
As defined by the derived class.
Guideline: 0 means success.

bool OSB_APP::ThreadBase::running (  )  const

Thread (still) running?

virtual int OSB_APP::ThreadBase::start (  )  [virtual]

Start the thread via callThreadFunction.

Returns:
The return value of the thread: rc().
The functions first locks and then starts threadFunction() (via callThreadFunction()).
It then waits until the thread has initialized, ev. set an appropriate return value and unlocked.

int OSB_APP::ThreadBase::stop ( int  newStop  ) 

Set stop flag.

int OSB_APP::ThreadBase::stop (  )  const

Get stop flag.

virtual void OSB_APP::ThreadBase::threadFunction (  )  [protected, pure virtual]

The start function of the thread.

Attention:
The implementation must call unlock() after the initialization work (see also start()).
Note:
This also means that until unlock() is called, rc_ should be accessed unprotected (and not via rc()).

int OSB_APP::ThreadBase::unlock (  )  const [protected]

Unlock the mutex.


Friends And Related Function Documentation

void* callThreadFunction ( void *  threadBase  )  [friend]

Wrapper to ThreadBase::threadFunction.

Its signature must meet the requirement of pthread_create(...), i.e. we have to avoid the implicit this pointer that is added to non-static member functions.

Parameters:
threadBase Pointer to the instance of ThreadBase for which ThreadBase::start() was called (its this pointer).
Returns:
Always 0: any return value of the thread should be in members of derived classes.
Note:
Because of its C linkage, it must be declared before being named friend in ThreadBase.


Member Data Documentation

int OSB_APP::ThreadBase::id_

User assigned id of the thread.

Definition at line 130 of file osbthread.h.

pthread_mutex_t OSB_APP::ThreadBase::mutex_ [mutable, protected]

Mutex to protect member data.

Definition at line 169 of file osbthread.h.

int OSB_APP::ThreadBase::rc_ [protected]

Return value of the thread.

Definition at line 165 of file osbthread.h.

bool OSB_APP::ThreadBase::running_ [private]

Flag if the thread is (still) running.

This flag is set to true in start() and set to false in callThreadFunction() after threadFunction() has returned.

Definition at line 159 of file osbthread.h.

int OSB_APP::ThreadBase::stop_ [protected]

Stop flag: a value of 0 means continue working.

Definition at line 163 of file osbthread.h.

pthread_t OSB_APP::ThreadBase::thread_ [protected]

The actual thread object.

Definition at line 167 of file osbthread.h.


The documentation for this class was generated from the following file:
Generated on Sat Sep 2 14:17:30 2006 for OSB Library by  doxygen 1.4.7