Lunchbox  1.6.0
Public Member Functions | Static Public Member Functions | Public Types | Friends
lunchbox::Thread Class Reference

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

#include <thread.h>

List of all members.

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 *)

Detailed Description

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

Definition at line 36 of file thread.h.


Member Enumeration Documentation

Enumeration values for thread affinity.

Enumerator:
NONE 

Don't set any affinity.

CORE 

Bind to a specific CPU core.

SOCKET 

Bind to all cores of a specific socket (CPU)

SOCKET_MAX 

Highest bindable CPU.

Definition at line 40 of file thread.h.


Constructor & Destructor Documentation

Construct a new thread.

Version:
1.0
lunchbox::Thread::Thread ( const Thread from)

Copy constructor.

Version:
1.1.2
virtual lunchbox::Thread::~Thread ( ) [virtual]

Destruct the thread.

Version:
1.0

Member Function Documentation

Cancel (stop) the child thread.

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

Version:
1.0
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.

Version:
1.0
Returns:
a unique identifier for the calling thread.
Version:
1.0
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.

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

Definition at line 78 of file thread.h.

Returns:
true if the calling thread is the same thread as this thread, false otherwise.
Version:
1.0

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

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

Wait for the exit of the child thread.

Returns:
true if the thread was joined, false otherwise.
Version:
1.0
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().

Version:
1.0
virtual bool lunchbox::Thread::start ( ) [virtual]

Start the thread.

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

The documentation for this class was generated from the following file: