eq::base::Thread Class Reference

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

#include <thread.h>

Inheritance diagram for eq::base::Thread:
Inheritance graph
[legend]
Collaboration diagram for eq::base::Thread:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Thread ()
 Construct a new thread.
virtual ~Thread ()
 Destruct the thread.
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 void exit (void *retVal=0)
 Exit the child thread immediately.
void cancel ()
 Cancel (stop) the child thread.
bool join (void **retVal=0)
 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.
bool isCurrent () const
 Returns if this thread object is the current (calling) thread.

Static Public Member Functions

static void addListener (ExecutionListener *listener)
 Add a new thread state listener.
static bool removeListener (ExecutionListener *listener)
 Remove a thread state listener.
static void removeAllListeners ()
 Remove all registered listeners, used at exit.
static size_t getSelfThreadID ()
static void pinCurrentThread ()

Friends

void _notifyStopping (void *)
std::ostream & operator<< (std::ostream &os, const Thread *)

Detailed Description

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

Definition at line 44 of file thread.h.


Constructor & Destructor Documentation

eq::base::Thread::Thread (  ) 

Construct a new thread.

Version:
1.0

Definition at line 92 of file thread.cpp.

eq::base::Thread::~Thread (  )  [virtual]

Destruct the thread.

Version:
1.0

Definition at line 102 of file thread.cpp.


Member Function Documentation

bool eq::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

Definition at line 177 of file thread.cpp.

References EQVERB, EQWARN, and eq::base::Monitor< T >::waitNE().

Here is the call graph for this function:

virtual bool eq::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 77 of file thread.h.

virtual void* eq::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().

Returns:
the return value of the child thread.
Version:
1.0

Implemented in eq::Node::TransmitThread.

void eq::base::Thread::exit ( void *  retVal = 0  )  [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.

Parameters:
retVal the return value of the thread.
Version:
1.0

Definition at line 211 of file thread.cpp.

References EQINFO, and isCurrent().

Here is the call graph for this function:

void eq::base::Thread::cancel (  ) 

Cancel (stop) the child thread.

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

Version:
1.0

Definition at line 226 of file thread.cpp.

References EQINFO, and isCurrent().

Here is the call graph for this function:

bool eq::base::Thread::join ( void **  retVal = 0  ) 

Wait for the exit of the child thread.

Parameters:
retVal output value for the return value of the child, can be 0.
Returns:
true if the thread was joined, false otherwise.
Version:
1.0

Definition at line 237 of file thread.cpp.

References EQVERB, EQWARN, isCurrent(), and eq::base::Monitor< T >::waitNE().

Here is the call graph for this function:

bool eq::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 128 of file thread.h.

bool eq::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 139 of file thread.h.

bool eq::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

Definition at line 263 of file thread.cpp.

Referenced by cancel(), exit(), and join().

Here is the caller graph for this function:

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

Add a new thread state listener.

Parameters:
listener the listener.
Version:
1.0

Definition at line 277 of file thread.cpp.

bool eq::base::Thread::removeListener ( ExecutionListener listener  )  [static]

Remove a thread state listener.

Parameters:
listener the listener.
Version:
1.0

Definition at line 283 of file thread.cpp.

void eq::base::Thread::removeAllListeners (  )  [static]

Remove all registered listeners, used at exit.

Version:
1.0

Definition at line 297 of file thread.cpp.

References EQINFO.

size_t eq::base::Thread::getSelfThreadID (  )  [static]
Returns:
a unique identifier for the calling thread.
Version:
1.0

Definition at line 268 of file thread.cpp.

void eq::base::Thread::pinCurrentThread (  )  [static]

For internal use only.

Definition at line 317 of file thread.cpp.

References EQINFO, and EQWARN.


Friends And Related Function Documentation

void _notifyStopping ( void *  arg  )  [friend]

For internal use only.

Definition at line 155 of file thread.cpp.


The documentation for this class was generated from the following files:
Generated on Sat Feb 6 13:08:30 2010 for Equalizer 0.9.1 by  doxygen 1.6.1