Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_thread_thread_POSIX Class Reference

Platform specific thread_thread for POSIX platforms. More...

#include <LOW_thread_thread_POSIX.h>

Inheritance diagram for LOW_thread_thread_POSIX:

Inheritance graph
[legend]
Collaboration diagram for LOW_thread_thread_POSIX:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual ~LOW_thread_thread_POSIX ()
 Destructor.

 class_DERIVE_FROM_EXCEPTION (thread_thread_error, LOW_exception)
 Exception base class for all exceptions thrown by LOW_thread_thread.

 class_DERIVE_FROM_EXCEPTION (thread_thread_permission, thread_thread_error)
 Exception class indicating insufficient access rights.

 class_DERIVE_FROM_EXCEPTION (thread_thread_notAvailable, thread_thread_error)
 Exception class indicating that an option method is not implemented.

Methods callable by any thread.
virtual bool getIsStarted () const
 Indicates if the thread was started.

virtual bool getIsTerminated () const
 Indicates if the thread has terminated.

virtual int getReturnValue () const
 Get the return value of the thread.

virtual void create ()
 Actually create the thread and starts it's runnable's run() method.

virtual void cancel ()
 Cancel the execution of the thread.

virtual int join ()
 Wait for the termination of the thread.

virtual void detach ()
 Put a running thread in the detached state.

virtual void setScheduling (const LOW_thread_Factory::schedPolicy_t inPolicy, const LOW_thread_Factory::schedPrio_t inPrio)
 Set policy and parameter of scheduling.

virtual LOW_thread_Factory::schedPolicy_t getSchedPolicy () const
 Get the scheduling policy.

virtual LOW_thread_Factory::schedPrio_t getSchedPrio () const
 Get the scheduling parameter.

virtual LOW_thread_Factory::cancelAttrib_t getCancelAttrib () const
 Get cancelling behaviour.

Methods only callable by the own thread.
virtual void thread_exit (const int inRetVal)
 Terminate the calling thread.

virtual void testCancel ()
 Test on pending cancellation.

virtual void setCancelAttrib (const LOW_thread_Factory::cancelAttrib_t inCancelAttrib)
 Set cancelling behaviour.

Methods callable by any thread.
virtual bool getDetachAvialable () const
 Indicate if thread detaching is available.

virtual bool getScheduleModifyAvailable () const
 Indicate if thread scheduling modification is available.

virtual bool getCancelAttribsAvialable () const
 Indicate if thread cancelling attributes are available.


Static Public Attributes

const LOW_thread_Factory::schedPrio_t schedPrio_default = -1
 indicator for default scheduling priority


Protected Member Functions

 LOW_thread_thread_POSIX (LOW_thread_runable *inRunable, const LOW_thread_Factory::detachState_t inDetachState=LOW_thread_Factory::detachState_default, const LOW_thread_Factory::schedPolicy_t inSchedPolicy=LOW_thread_Factory::schedPolicy_default, const LOW_thread_Factory::schedPrio_t inSchedPrio=schedPrio_default)
 Constructor.

 LOW_thread_thread_POSIX ()
 Constructor.


Static Private Member Functions

void * threadRunner (void *inLaunchMe)
 Helper method for thread launching.


Private Attributes

LOW_thread_runablemyRunable
 Object providing the run() method.

pthread_attr_t initAttr
 Initial thread attributes.

pthread_t threadID
 ID of the thread.

bool isStarted
 Indicates that thread was launched.

bool isTerminated
 Indicated that thread has terminated.

int returnValue
 Return Value of run() method.

LOW_thread_Factory::cancelAttrib_t cancelAttrib
 Current cancel attribute.

LOW_thread_mutexcreateSyncMutex
 Mutex to synchronize with threadRunner on creation.


Friends

class LOW_thread_Factory
 To allow construction.


Detailed Description

Platform specific thread_thread for POSIX platforms.

This class is thread-safe.

Todo:
PROVIDE ASSIGNMENT OPERATOR

Throw more fine grained exceptions.

See also:
LOW_thread_thread

IEEE Standard 1003.1-2003 (http://www.opengroup.org/onlinepubs/007904975/toc.htm)

Author:
Harald Roelle

Parts of the documentation taken from Linux man pages by Xavier Leroy.

Parts of the documentation taken from IEEE Standard 1003.1-2003.

Definition at line 43 of file LOW_thread_thread_POSIX.h.


Constructor & Destructor Documentation

LOW_thread_thread_POSIX::~LOW_thread_thread_POSIX  )  [virtual]
 

Destructor.

Definition at line 91 of file LOW_thread_thread_POSIX.cpp.

References createSyncMutex, initAttr, LOW_helper_msglog::printPerror(), and threadID.

LOW_thread_thread_POSIX::LOW_thread_thread_POSIX LOW_thread_runable inRunable,
const LOW_thread_Factory::detachState_t  inDetachState = LOW_thread_Factory::detachState_default,
const LOW_thread_Factory::schedPolicy_t  inSchedPolicy = LOW_thread_Factory::schedPolicy_default,
const LOW_thread_Factory::schedPrio_t  inSchedPrio = schedPrio_default
[protected]
 

Constructor.

Not publicly constructable. Use LOW_thread_Factory.

Parameters:
inDetachState 
inSchedPolicy 
inSchedPrio 

Definition at line 33 of file LOW_thread_thread_POSIX.cpp.

References createSyncMutex, initAttr, isStarted, isTerminated, LOW_thread_mutex::mutexKind_errorCheck, myRunable, LOW_thread_Factory::new_mutex(), and schedPrio_default.

LOW_thread_thread_POSIX::LOW_thread_thread_POSIX  )  [protected]
 

Constructor.

Not publicly constructable. Use LOW_thread_Factory.


Member Function Documentation

void LOW_thread_thread_POSIX::cancel  )  [virtual]
 

Cancel the execution of the thread.

Note that the thread is not forced to quit. Cancellation of POSIX threads depends on cancel state and cancel type. The thread can then either ignore the request, honor it immediately, or defer it till it reaches a cancellation point.

Exceptions:
thread_thread_error On any error.

Implements LOW_thread_thread.

Definition at line 147 of file LOW_thread_thread_POSIX.cpp.

References threadID.

LOW_thread_thread::class_DERIVE_FROM_EXCEPTION thread_thread_notAvailable  ,
thread_thread_error 
[inherited]
 

Exception class indicating that an option method is not implemented.

LOW_thread_thread::class_DERIVE_FROM_EXCEPTION thread_thread_permission  ,
thread_thread_error 
[inherited]
 

Exception class indicating insufficient access rights.

LOW_thread_thread::class_DERIVE_FROM_EXCEPTION thread_thread_error  ,
LOW_exception 
[inherited]
 

Exception base class for all exceptions thrown by LOW_thread_thread.

void LOW_thread_thread_POSIX::create  )  [virtual]
 

Actually create the thread and starts it's runnable's run() method.

Execution is synchronized with threadRunner() via createSyncMutex.

Exceptions:
thread_thread_error On any error.

Implements LOW_thread_thread.

Definition at line 133 of file LOW_thread_thread_POSIX.cpp.

References createSyncMutex, getIsStarted(), initAttr, isStarted, threadID, and threadRunner().

void LOW_thread_thread_POSIX::detach  )  [virtual]
 

Put a running thread in the detached state.

Puts the thread in the detached state. This guarantees that the memory resources consumed by will be freed immediately when it terminates. This also prevents other threads from synchronizing on the termination using join().

A thread can be created initially in the detached state, appropriate constructor argument. In contrast, detach() applies to threads created in the joinable state, and which need to be put in the detached state later.

After detach() completes, subsequent attempts to perform join() on it will fail. If another thread is already joining the thread at the time detach() is called, detach() does nothing and leaves the thread in the joinable state.

Exceptions:
thread_thread_error On any error.

Reimplemented from LOW_thread_thread.

Definition at line 163 of file LOW_thread_thread_POSIX.cpp.

References threadID.

LOW_thread_Factory::cancelAttrib_t LOW_thread_thread_POSIX::getCancelAttrib  )  const [virtual]
 

Get cancelling behaviour.

Exceptions:
thread_thread_error On any error.

Reimplemented from LOW_thread_thread.

Definition at line 204 of file LOW_thread_thread_POSIX.cpp.

References cancelAttrib, getIsStarted(), and getIsTerminated().

bool LOW_thread_thread::getCancelAttribsAvialable  )  const [virtual, inherited]
 

Indicate if thread cancelling attributes are available.

Definition at line 73 of file LOW_thread_thread.cpp.

bool LOW_thread_thread::getDetachAvialable  )  const [virtual, inherited]
 

Indicate if thread detaching is available.

Definition at line 37 of file LOW_thread_thread.cpp.

bool LOW_thread_thread_POSIX::getIsStarted  )  const [virtual]
 

Indicates if the thread was started.

Returns:
Bool indicating if thread was started.

Implements LOW_thread_thread.

Definition at line 109 of file LOW_thread_thread_POSIX.cpp.

References isStarted.

Referenced by create(), getCancelAttrib(), and getReturnValue().

bool LOW_thread_thread_POSIX::getIsTerminated  )  const [virtual]
 

Indicates if the thread has terminated.

Returns:
Bool indicating if thread has terminated.

Implements LOW_thread_thread.

Definition at line 115 of file LOW_thread_thread_POSIX.cpp.

References isTerminated.

Referenced by getCancelAttrib(), and getReturnValue().

int LOW_thread_thread_POSIX::getReturnValue  )  const [virtual]
 

Get the return value of the thread.

Returns:
Return value of terminated thread.
Exceptions:
thread_thread_error When thread has not terminated yet.

Implements LOW_thread_thread.

Definition at line 121 of file LOW_thread_thread_POSIX.cpp.

References getIsStarted(), getIsTerminated(), and returnValue.

LOW_thread_Factory::schedPolicy_t LOW_thread_thread_POSIX::getSchedPolicy  )  const [virtual]
 

Get the scheduling policy.

Exceptions:
thread_thread_error On any error.

Reimplemented from LOW_thread_thread.

Definition at line 180 of file LOW_thread_thread_POSIX.cpp.

References threadID.

LOW_thread_Factory::schedPrio_t LOW_thread_thread_POSIX::getSchedPrio  )  const [virtual]
 

Get the scheduling parameter.

Exceptions:
thread_thread_error On any error.

Reimplemented from LOW_thread_thread.

Definition at line 192 of file LOW_thread_thread_POSIX.cpp.

References threadID.

bool LOW_thread_thread::getScheduleModifyAvailable  )  const [virtual, inherited]
 

Indicate if thread scheduling modification is available.

Definition at line 49 of file LOW_thread_thread.cpp.

int LOW_thread_thread_POSIX::join  )  [virtual]
 

Wait for the termination of the thread.

Suspends the execution of the calling thread until the thread terminates, either by calling thread_exit() or by being cancelled.

The thread must be in the joinable state: it must not have been detached using detach() or constructed as detached.

When a joinable thread terminates, its memory resources (thread descriptor and stack) are not deallocated until another thread performs join() on it. Therefore, join() must be called once for each joinable thread created to avoid memory leaks. When class is destructed the destructor takes care of this.

At most one thread can wait for the termination of a thread. Calling join() on a thread on which another thread is already waiting for termination throws an exception.

Implementation is mandatory.

Exceptions:
thread_thread_error On any error.
See also:
detach()

Implements LOW_thread_thread.

Definition at line 154 of file LOW_thread_thread_POSIX.cpp.

References returnValue, and threadID.

void LOW_thread_thread_POSIX::setCancelAttrib const LOW_thread_Factory::cancelAttrib_t  inCancelAttrib  )  [virtual]
 

Set cancelling behaviour.

Changes the cancellation state for the calling thread -- that is, whether cancellation requests are ignored or not and when they are handled.

Parameters:
inCancelAttrib Cancelling handling attribute to set.
Exceptions:
thread_thread_permission Calling thread is not the object's thread.
thread_thread_error On any other error.

Reimplemented from LOW_thread_thread.

Definition at line 233 of file LOW_thread_thread_POSIX.cpp.

References cancelAttrib, and threadID.

Referenced by threadRunner().

void LOW_thread_thread_POSIX::setScheduling const LOW_thread_Factory::schedPolicy_t  inPolicy,
const LOW_thread_Factory::schedPrio_t  inPrio
[virtual]
 

Set policy and parameter of scheduling.

Parameters:
inPolicy Scheduling policy to apply.
inPolicy Scheduling parameter to apply.
Exceptions:
thread_thread_error On any error.

Reimplemented from LOW_thread_thread.

Definition at line 170 of file LOW_thread_thread_POSIX.cpp.

References threadID.

void LOW_thread_thread_POSIX::testCancel  )  [virtual]
 

Test on pending cancellation.

Method does nothing except testing for pending cancellation and executing it. Its purpose is to introduce explicit checks for cancellation in long sequences of code that do not call cancellation point functions otherwise.

Exceptions:
thread_thread_permission Calling thread is not the object's thread.
thread_thread_error On any other error.
See also:
cancel()

Implements LOW_thread_thread.

Definition at line 224 of file LOW_thread_thread_POSIX.cpp.

References threadID.

void LOW_thread_thread_POSIX::thread_exit const int  inRetVal  )  [virtual]
 

Terminate the calling thread.

Method can only be called by the own thread.

Parameters:
inRetVal Return value to quit with.
Exceptions:
thread_thread_permission Calling thread is not the object's thread.
thread_thread_error On any other error.

Implements LOW_thread_thread.

Definition at line 215 of file LOW_thread_thread_POSIX.cpp.

References threadID.

void * LOW_thread_thread_POSIX::threadRunner void *  inLaunchMe  )  [static, private]
 

Helper method for thread launching.

This method gives the possibility to interface with OS-specific calls which require C-style linkage conventions.

Note that when imlementing such a method, special care about thread-safety must be taken.

Reimplemented from LOW_thread_thread.

Definition at line 271 of file LOW_thread_thread_POSIX.cpp.

References createSyncMutex, isTerminated, myRunable, returnValue, LOW_thread_runable::run(), and setCancelAttrib().

Referenced by create().


Friends And Related Function Documentation

friend class LOW_thread_Factory [friend]
 

To allow construction.

Definition at line 251 of file LOW_thread_thread_POSIX.h.


Member Data Documentation

LOW_thread_Factory::cancelAttrib_t LOW_thread_thread_POSIX::cancelAttrib [private]
 

Current cancel attribute.

Definition at line 292 of file LOW_thread_thread_POSIX.h.

Referenced by getCancelAttrib(), and setCancelAttrib().

LOW_thread_mutex* LOW_thread_thread_POSIX::createSyncMutex [private]
 

Mutex to synchronize with threadRunner on creation.

Definition at line 293 of file LOW_thread_thread_POSIX.h.

Referenced by create(), LOW_thread_thread_POSIX(), threadRunner(), and ~LOW_thread_thread_POSIX().

pthread_attr_t LOW_thread_thread_POSIX::initAttr [private]
 

Initial thread attributes.

Definition at line 287 of file LOW_thread_thread_POSIX.h.

Referenced by create(), LOW_thread_thread_POSIX(), and ~LOW_thread_thread_POSIX().

bool LOW_thread_thread_POSIX::isStarted [private]
 

Indicates that thread was launched.

Definition at line 289 of file LOW_thread_thread_POSIX.h.

Referenced by create(), getIsStarted(), and LOW_thread_thread_POSIX().

bool LOW_thread_thread_POSIX::isTerminated [private]
 

Indicated that thread has terminated.

Definition at line 290 of file LOW_thread_thread_POSIX.h.

Referenced by getIsTerminated(), LOW_thread_thread_POSIX(), and threadRunner().

LOW_thread_runable* LOW_thread_thread_POSIX::myRunable [private]
 

Object providing the run() method.

Definition at line 286 of file LOW_thread_thread_POSIX.h.

Referenced by LOW_thread_thread_POSIX(), and threadRunner().

int LOW_thread_thread_POSIX::returnValue [private]
 

Return Value of run() method.

Definition at line 291 of file LOW_thread_thread_POSIX.h.

Referenced by getReturnValue(), join(), and threadRunner().

const LOW_thread_Factory::schedPrio_t LOW_thread_thread_POSIX::schedPrio_default = -1 [static]
 

indicator for default scheduling priority

Definition at line 53 of file LOW_thread_thread_POSIX.h.

Referenced by LOW_thread_thread_POSIX().

pthread_t LOW_thread_thread_POSIX::threadID [private]
 

ID of the thread.

Definition at line 288 of file LOW_thread_thread_POSIX.h.

Referenced by cancel(), create(), detach(), getSchedPolicy(), getSchedPrio(), join(), setCancelAttrib(), setScheduling(), testCancel(), thread_exit(), and ~LOW_thread_thread_POSIX().


The documentation for this class was generated from the following files:
Generated on Tue Feb 3 11:31:09 2004 for OneWireLibrary++ by doxygen 1.3.2