Lunchbox
1.4.0
|
An utility class to execute code in a separate execution thread. More...
#include <thread.h>
Public Member Functions | |
Thread () | |
Construct a new thread. | |
Thread (const Thread &from) | |
Copy constructor. | |
virtual | ~Thread () |
Destruct the thread. | |
virtual 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 () |
Exit the child thread immediately. | |
void | cancel () |
Cancel (stop) the child thread. | |
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. | |
bool | isCurrent () const |
Static Public Member Functions | |
static ThreadID | getSelfThreadID () |
static void | yield () |
static void | pinCurrentThread () |
static void | setName (const std::string &name) |
static void | setAffinity (const int32_t affinity) |
Public Types | |
enum | Affinity { NONE = 0, CORE = 1, SOCKET = -65536, SOCKET_MAX = -1024 } |
Enumeration values for thread affinity. More... | |
Friends | |
void | _notifyStopping (void *) |
An utility class to execute code in a separate execution thread.
Construct a new thread.
lunchbox::Thread::Thread | ( | const Thread & | from | ) |
Copy constructor.
virtual lunchbox::Thread::~Thread | ( | ) | [virtual] |
Destruct the thread.
void lunchbox::Thread::cancel | ( | ) |
Cancel (stop) the child thread.
This function is not to be called from the child thread.
virtual void lunchbox::Thread::exit | ( | ) | [virtual] |
Exit the child thread immediately.
This function does not return. It is only to be called from the child thread.
static ThreadID lunchbox::Thread::getSelfThreadID | ( | ) | [static] |
virtual bool lunchbox::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.
bool lunchbox::Thread::isCurrent | ( | ) | const |
bool lunchbox::Thread::isRunning | ( | ) | const |
Return if the thread is running.
Note that the thread may be neither running nor stopped if it is currently starting or stopping.
bool lunchbox::Thread::isStopped | ( | ) | const |
Return if the thread is stopped.
Note that the thread may be neither running nor stopped if it is currently starting or stopping.
bool lunchbox::Thread::join | ( | ) |
Wait for the exit of the child thread.
virtual void lunchbox::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().
virtual bool lunchbox::Thread::start | ( | ) | [virtual] |