Equalizer 1.0

co::base::Thread Class Reference

An utility class to execute code in a separate execution thread. More...

#include <thread.h>

Inheritance diagram for co::base::Thread:
Collaboration diagram for co::base::Thread:

List of all members.

Public Member Functions

COBASE_API Thread ()
 Construct a new thread.
virtual COBASE_API ~Thread ()
 Destruct the thread.
COBASE_API bool start ()
 Start the thread.
virtual bool init ()
 The init function for the child thread.
virtual void run ()=0
 The entry function for the child thread.
virtual COBASE_API void exit ()
 Exit the child thread immediately.
COBASE_API void cancel ()
 Cancel (stop) the child thread.
COBASE_API bool join ()
 Wait for the exit of the child thread.
bool isStopped () const
 Return if the thread is stopped.
bool isRunning () const
 Return if the thread is running.
COBASE_API bool isCurrent () const
 Returns if this thread object is the current (calling) thread.
COBASE_API void untrack ()

Static Public Member Functions

static COBASE_API void addListener (ExecutionListener *listener)
 Add a new thread state listener.
static COBASE_API bool removeListener (ExecutionListener *listener)
 Remove a thread state listener.
static COBASE_API void removeAllListeners ()
 Remove all registered listeners, used at exit.
static COBASE_API ThreadID getSelfThreadID ()
static COBASE_API void yield ()
static void pinCurrentThread ()
static COBASE_API void setName (const std::string &name)

Friends

void _notifyStopping (void *)
std::ostream & operator<< (std::ostream &os, const Thread *)
 Print the thread to the given output stream.

Detailed Description

An utility class to execute code in a separate execution thread.

Definition at line 36 of file thread.h.


Constructor & Destructor Documentation

COBASE_API co::base::Thread::Thread ( )

Construct a new thread.

Version:
1.0
virtual COBASE_API co::base::Thread::~Thread ( ) [virtual]

Destruct the thread.

Version:
1.0

Member Function Documentation

static COBASE_API void co::base::Thread::addListener ( ExecutionListener listener) [static]

Add a new thread state listener.

Parameters:
listenerthe listener.
Version:
1.0
COBASE_API void co::base::Thread::cancel ( )

Cancel (stop) the child thread.

This function is not to be called from the child thread.

Version:
1.0
virtual COBASE_API void co::base::Thread::exit ( ) [virtual]

Exit the child thread immediately.

This function does not return. It is only to be called from the child thread. The thread listeners will be notified.

Version:
1.0
static COBASE_API ThreadID co::base::Thread::getSelfThreadID ( ) [static]
Returns:
a unique identifier for the calling thread.
Version:
1.0
virtual bool co::base::Thread::init ( ) [inline, virtual]

The init function for the child thread.

The parent thread will not be unlocked before this function has been executed. If the thread initialization fails, that is, this method does return false, the thread will be stopped and the start() method will return false.

Returns:
the success value of the thread initialization.
Version:
1.0

Definition at line 69 of file thread.h.

COBASE_API bool co::base::Thread::isCurrent ( ) const

Returns if this thread object is the current (calling) thread.

Returns:
true if the current thread has is the same thread as this thread, false if not.
Version:
1.0
bool co::base::Thread::isRunning ( ) const [inline]

Return if the thread is running.

Note that the thread may be neither running nor stopped if it is currently starting or stopping.

Returns:
true if the thread is running, false if not.
Version:
1.0

Definition at line 127 of file thread.h.

bool co::base::Thread::isStopped ( ) const [inline]

Return if the thread is stopped.

Note that the thread may be neither running nor stopped if it is currently starting or stopping.

Returns:
true if the thread is stopped, false if not.
Version:
1.0

Definition at line 116 of file thread.h.

COBASE_API bool co::base::Thread::join ( )

Wait for the exit of the child thread.

Returns:
true if the thread was joined, false otherwise.
Version:
1.0
static COBASE_API void co::base::Thread::removeAllListeners ( ) [static]

Remove all registered listeners, used at exit.

Version:
1.0
static COBASE_API bool co::base::Thread::removeListener ( ExecutionListener listener) [static]

Remove a thread state listener.

Parameters:
listenerthe listener.
Version:
1.0
virtual void co::base::Thread::run ( ) [pure virtual]

The entry function for the child thread.

This method should contain the main execution routine for the thread and is called after a successful init().

Version:
1.0

Implemented in eq::Node::TransmitThread.

COBASE_API bool co::base::Thread::start ( )

Start the thread.

All thread state listeners will be notified from the new thread, after the thread was initialized successfully.

Returns:
true if the thread was launched and initialized successfully, false otherwise.
See also:
init(), run(), addListener()
Version:
1.0

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const Thread  
) [friend]

Print the thread to the given output stream.


The documentation for this class was generated from the following file:
Generated on Sun May 8 2011 19:11:09 for Equalizer 1.0 by  doxygen 1.7.3