Home C-Bits Package Documentation Project Page

Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cbits::Thread_PTHREAD Class Reference

PTHREAD implementation of the cbits::Thread class. More...

#include <Thread_PTHREAD.h>

Inheritance diagram for cbits::Thread_PTHREAD:

[legend]
Collaboration diagram for cbits::Thread_PTHREAD:
[legend]
List of all members.

Public Types

enum  State { READY = 1, ALIVE = 2, DEAD = 3 }
 Thread states. More...

enum  Priority {
  PRIORITY_1 = 1, PRIORITY_2 = 2, PRIORITY_3 = 3, PRIORITY_4 = 4,
  PRIORITY_5 = 5, PRIORITY_6 = 6, PRIORITY_7 = 7, PRIORITY_8 = 8,
  PRIORITY_9 = 9, MIN_PRIORITY = PRIORITY_1, DEFAULT_PRIORITY = PRIORITY_5, MAX_PRIORITY = PRIORITY_9
}
 Thread scheduling priorities. More...


Public Methods

 Thread_PTHREAD (Runnable *r, const Priority p=DEFAULT_PRIORITY)
 Constructor. More...

virtual ~Thread_PTHREAD ()
 Destructor. More...

void start ()
 Start the thread. More...

const long getThreadID () const
 Get Thread's ID. More...

void interrupt ()
 Send a event to the thread. More...

const bool join (const long msec=0)
 Wait for this thread to terminate. More...

const State getState (const bool lockit=true) const
 Get this thread's run state. More...

void setData (void *) const
 Associate user data with this thread. More...

void * getData () const
 Retrieve user data that has been associated with this thread (if any). More...


Static Public Methods

Threadget_current_thread ()
 Get a pointer to the current thread. More...

void yield ()
 Yield the processor. More...

Threadcreate (Runnable *r, const Priority p=DEFAULT_PRIORITY)
 Factory method for creating thread objects. More...

ThreadgetCurrent ()
 Get reference to the current thread of execution. More...

const bool isInterrupted ()
 Check the interrupt status of the current thread. More...

void sleep (const long msec)
 Put current thread to sleep. More...


Protected Methods

virtual const bool impl_create_thread (const Priority)
 Create a platform-specific thread. More...

virtual const bool impl_start_thread ()
 Start the platform-specific thread. More...

virtual const long impl_get_threadid () const
 Get thread's ID. More...

virtual void impl_lock_obj () const
 Lock this thread object. More...

virtual void impl_unlock_obj () const
 Unlock this thread object. More...

virtual void impl_interrupt ()
 Send an 'interrupt' event to the platform-specific thread implementation. More...

virtual const bool impl_join (const long msec)
 Wait for the platform thread to terminate. More...

virtual void impl_sleep (const long msec)
 Put the current thread to sleep. More...

RunnablegetTarget () const
 Get a reference to the user-supplied execution object. More...

const State setState (State, const bool lockit=true)
 Set the state of the thread. More...

void setError (const char *e) const
 Set the error string that describes the most recent error. More...

const std::string & getError () const
 Get the an explanation of the last error that occurred (if any). More...

const Priority getPriority () const
 Get the thread's scheduling priority. More...


Private Methods

const long getTid () const
 Get this thread's THREAD ID. More...


Static Private Methods

void * run_thread (void *thread_ptr)
 Entry point for p-thread. More...

void cleanup (void *t)
 Cleanup handler. More...

std::list< Thread_PTHREAD * > & getThreadList ()
 Accessor for thread list. More...


Private Attributes

long _tid
 ID of the underling posix thread. More...


Static Private Attributes

std::list< Thread_PTHREAD * > _threads
 Thread list. More...


Detailed Description

PTHREAD implementation of the cbits::Thread class.

This Thread implementation may be used on platforms that support a POSIX threads implementation.


Member Enumeration Documentation

enum cbits::Thread::Priority [inherited]
 

Thread scheduling priorities.

Enumeration values:
PRIORITY_1 
PRIORITY_2 
PRIORITY_3 
PRIORITY_4 
PRIORITY_5 
PRIORITY_6 
PRIORITY_7 
PRIORITY_8 
PRIORITY_9 
MIN_PRIORITY 
DEFAULT_PRIORITY 
MAX_PRIORITY 

enum cbits::Thread::State [inherited]
 

Thread states.

Enumeration values:
READY 
ALIVE  Thread is read to execute.
DEAD  Thread is executing.


Constructor & Destructor Documentation

Thread_PTHREAD::Thread_PTHREAD Runnable   r,
const Priority    p = DEFAULT_PRIORITY
 

Constructor.

Parameters:
r  User-supplied execution object.
p  Scheduling priority of the new thread

Thread_PTHREAD::~Thread_PTHREAD   [virtual]
 

Destructor.


Member Function Documentation

void Thread_PTHREAD::cleanup void *    t [static, private]
 

Cleanup handler.

Parameters:
t  Pointer to the Thread_PTHREAD instance

Thread * Thread::create Runnable   r,
const Priority    p = DEFAULT_PRIORITY
[static, inherited]
 

Factory method for creating thread objects.

Returns:
pointer to new thread object in the READY state.
Parameters:
p  User supplied object to execute Thread priority

Thread * Thread_PTHREAD::get_current_thread   [static]
 

Get a pointer to the current thread.

Returns:
pointer to Thread object if this thread was created as an instance of Thread; otherwise a 0 is returned.

Thread * Thread::getCurrent   [static, inherited]
 

Get reference to the current thread of execution.

Returns:
pointer to current thread, or 0 if the current thread was not created as an instance of Thread.

void * Thread::getData   const [inherited]
 

Retrieve user data that has been associated with this thread (if any).

Returns:
pointer to opaque user supplied data object.

const std::string& cbits::Thread::getError   const [inline, protected, inherited]
 

Get the an explanation of the last error that occurred (if any).

This method is only available to the implementation-specific derived class.

Returns:
reference to a string that contains a message that describes the last error that occurred. If no errors have occurred, then the string may be empty.

const Priority cbits::Thread::getPriority   const [inline, protected, inherited]
 

Get the thread's scheduling priority.

This method is only available to the implementation-specific derived class.

Returns:
a element of the Priority ennumeration.

const Thread::State Thread::getState const bool    lockit = true const [inherited]
 

Get this thread's run state.

Runnable* cbits::Thread::getTarget   const [inline, protected, inherited]
 

Get a reference to the user-supplied execution object.

Returns:
pointer to user-supplied Runnable instance.

const long Thread::getThreadID   const [inherited]
 

Get Thread's ID.

Returns:
long integer representing thread's ID.

std::list< Thread_PTHREAD * > & Thread_PTHREAD::getThreadList   [static, private]
 

Accessor for thread list.

const long Thread_PTHREAD::getTid   const [private]
 

Get this thread's THREAD ID.

Returns:
thread ID as a long.

virtual const bool cbits::Thread_PTHREAD::impl_create_thread const    Priority [protected, virtual]
 

Create a platform-specific thread.

This method must be implemented by the platform-specific derived class.

Returns:
true if successful; otherwise false is returned and getError() must return a description of the error that occured.

Implements cbits::Thread.

const long Thread_PTHREAD::impl_get_threadid   const [protected, virtual]
 

Get thread's ID.

This method is called internally to prevent access to the thread object while it is modifying its internal state.

Returns:
long

Implements cbits::Thread.

void Thread_PTHREAD::impl_interrupt   [protected, virtual]
 

Send an 'interrupt' event to the platform-specific thread implementation.

This method must be implemented by the platform-specific derived class.

Implements cbits::Thread.

const bool Thread_PTHREAD::impl_join const long    msec [protected, virtual]
 

Wait for the platform thread to terminate.

This method must be implemented by the platform-specific derived class.

Returns:
true if the platform thread has exited. If an error occurs during the 'join', false is returned and getError() must return a description of the error that occured.

Implements cbits::Thread.

void Thread_PTHREAD::impl_lock_obj   const [protected, virtual]
 

Lock this thread object.

This method is called internally to prevent access to the thread object while it is modifying its internal state.

This method must be implemented by the platform-specific derived class.

Implements cbits::Thread.

void Thread_PTHREAD::impl_sleep const long    msec [protected, virtual]
 

Put the current thread to sleep.

This method must be implemented by the platform-specific derived class.

Implements cbits::Thread.

const bool Thread_PTHREAD::impl_start_thread   [protected, virtual]
 

Start the platform-specific thread.

This method must be implemented by the platform-specific derived class.

Returns:
true if successful; otherwise false is returned and getError() must return a description of the error that occured.

Implements cbits::Thread.

void Thread_PTHREAD::impl_unlock_obj   const [protected, virtual]
 

Unlock this thread object.

This method is called internally to release the lock that may have been set to prevent access to the thread object while it is modifying its internal state.

This method must be implemented by the platform-specific derived class.

Implements cbits::Thread.

void Thread::interrupt   [inherited]
 

Send a event to the thread.

It is intended that the Runnable code must be written in such a way that it is sensitive to the interrupt status of the thread. It may check the interrupt status by calling the 'isInterrupted' method.

const bool Thread::isInterrupted   [static, inherited]
 

Check the interrupt status of the current thread.

The interrupt state is reset after every call to this method.

Returns:
'true' if another thread has previously called the 'interrupt' method on this thread instance. otherwise, false is returned.

const bool Thread::join const long    msec = 0 [inherited]
 

Wait for this thread to terminate.

FIXME Thread.h 'msec' argument is ignored by 'join' method.

Parameters:
msec  maximum number of milliseconds to wait for the thread to end. 'msec' <= 0 is interpreted as 'wait forever'.

void * Thread_PTHREAD::run_thread void *    thread_ptr [static, private]
 

Entry point for p-thread.

See documentation for pthread_create.

Parameters:
t  Pointer to the Thread_PTHREAD instance

void Thread::setData void *    const [inherited]
 

Associate user data with this thread.

Parameters:
d  pointer to opaque user-supplied data object

void cbits::Thread::setError const char *    e const [inline, protected, inherited]
 

Set the error string that describes the most recent error.

This method is only available to the implementation-specific derived class.

Parameters:
e  An explanation of the last error

const Thread::State Thread::setState State   ,
const bool    lockit = true
[protected, inherited]
 

Set the state of the thread.

This method is only available to the implementation specific derived class.

Returns:
the old state.
Parameters:
lockit  true if object should be locked before changing state.

void Thread::sleep const long    msec [static, inherited]
 

Put current thread to sleep.

Parameters:
msec  Number of milliseconds to sleep. The process may wake up before the full interval has elapsed.

void Thread::start   [inherited]
 

Start the thread.

The Thread object's state changes from READY to ALIVE.

@raises ThreadException if :

  • the thread is in the DEAD state.
  • The platform thread cannot be started.

void Thread_PTHREAD::yield   [static]
 

Yield the processor.

Reimplemented from cbits::Thread.


Member Data Documentation

std::list< Thread_PTHREAD * > Thread_PTHREAD::_threads [static, private]
 

Thread list.

long cbits::Thread_PTHREAD::_tid [private]
 

ID of the underling posix thread.


The documentation for this class was generated from the following files:
Generated by
doxygen
Hosted by
SourceForge