Equalizer 1.0
|
An utility class to execute code in a separate execution thread. More...
#include <thread.h>
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. |
An utility class to execute code in a separate execution thread.
COBASE_API co::base::Thread::Thread | ( | ) |
Construct a new thread.
virtual COBASE_API co::base::Thread::~Thread | ( | ) | [virtual] |
Destruct the thread.
static COBASE_API void co::base::Thread::addListener | ( | ExecutionListener * | listener | ) | [static] |
Add a new thread state listener.
listener | the listener. |
COBASE_API void co::base::Thread::cancel | ( | ) |
Cancel (stop) the child thread.
This function is not to be called from the child thread.
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.
static COBASE_API ThreadID co::base::Thread::getSelfThreadID | ( | ) | [static] |
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.
COBASE_API bool co::base::Thread::isCurrent | ( | ) | const |
Returns if this thread object is the current (calling) thread.
bool co::base::Thread::isRunning | ( | ) | const [inline] |
bool co::base::Thread::isStopped | ( | ) | const [inline] |
COBASE_API bool co::base::Thread::join | ( | ) |
Wait for the exit of the child thread.
static COBASE_API void co::base::Thread::removeAllListeners | ( | ) | [static] |
Remove all registered listeners, used at exit.
static COBASE_API bool co::base::Thread::removeListener | ( | ExecutionListener * | listener | ) | [static] |
Remove a thread state listener.
listener | the listener. |
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().
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.
true
if the thread was launched and initialized successfully, false
otherwise. std::ostream& operator<< | ( | std::ostream & | os, |
const Thread * | |||
) | [friend] |
Print the thread to the given output stream.