Class for creating a thread. More...
Public Types | |
enum | eState { kStateInvalid , kStateRunning , kStateEnded , kStateDetached } |
Current state of the Thread class. More... | |
typedef uintptr_t(*) | FunctionPtr(void *pThis) |
Thread entry prototype. | |
Public Member Functions | |
Thread () noexcept | |
Initialize a thread to power up defaults. | |
~Thread () | |
Destructor. | |
eError | start (FunctionPtr pFunction, void *pData, const char *pName=nullptr, uintptr_t uStackSize=0) noexcept |
Startup a thread. | |
eError | wait (void) noexcept |
Wait for a thread to exit. | |
eError | detach (void) noexcept |
Detach a thread. | |
const char * | get_name (void) const noexcept |
Return the name of the thread. | |
uintptr_t | get_result (void) const noexcept |
Return the exit code of the user supplied thread. | |
uintptr_t | get_stack_size (void) const noexcept |
Return the size of the stack allocated for this thread. | |
uint_t | is_initialized (void) const noexcept |
Return TRUE if a thread is running. | |
Static Public Member Functions | |
static void | run (void *pThis) noexcept |
Internal function to dispatch to the thread. | |
Protected Member Functions | |
eError | platform_start (void) noexcept |
Internal function to start a thread. | |
eError | platform_after_start (void) noexcept |
Internal function to set up data specific to a thread. | |
eError | platform_detach (void) noexcept |
Internal function to detach a thread. | |
Protected Attributes | |
FunctionPtr | m_pFunction |
Pointer to the thread. | |
void * | m_pData |
Data pointer for the thread. | |
const char * | m_pName |
Name of the thread. | |
uintptr_t | m_uStackSize |
Size of the stack allocated for the thread. | |
uintptr_t | m_uResult |
Result code of the thread on exit. | |
ThreadID | m_uThreadID |
ThreadID assigned to this thread. | |
uint32_t | m_uState |
State of the thread, see /ref eState. | |
void * | m_pThreadHandle |
HANDLE to the thread (Windows/Xbox only) | |
uint8_t * | m_pStack |
Memory for the thread's stack. | |
void * | m_pOSThread |
Pointer to OSThread record. | |
Private Member Functions | |
Thread (const Thread &)=delete | |
Thread & | operator= (const Thread &)=delete |
Thread (Thread &&)=delete | |
Thread & | operator= (Thread &&)=delete |
Class for creating a thread.
In a multiprocessor system, it's sometimes necessary to have another CPU run a concurrent thread. This class will handle the dispatching a thread.
Further reading http://en.wikipedia.org/wiki/Thread_(computing)
uintptr_t( *) Burger::Thread::FunctionPtr(void *pThis) |
Thread entry prototype.
Current state of the Thread class.
Once a Thread class is instanciated, it's set to the kStateInvalid state. Once a thread has begun, the state value will be updated to reflect the state of the thread as it executes and possibly terminates.
Enumerator | |
---|---|
kStateInvalid | Thread has not been set up. |
kStateRunning | Thread is in progress. |
kStateEnded | Thread has concluded. |
kStateDetached | Thread was detached. |
|
privatedelete |
|
privatedelete |
|
noexcept |
Burger::Thread::~Thread | ( | ) |
Destructor.
Wait until the thread completes and then release resources
|
noexcept |
Detach a thread.
If a thread isn't already running, return immediately. If a thread is already running, alert the operating system that this thread should be aborted and shut down.
|
noexcept |
Return the name of the thread.
Returns either an empty string or the assigned name of the thread. This function will not return nullptr
|
inlinenoexcept |
Return the exit code of the user supplied thread.
When a thread launched by this class executes, it can return a result code which is captured by the dispatcher. The code can retrieved by this call.
|
inlinenoexcept |
Return the size of the stack allocated for this thread.
When a thread launched by this class, a stack is assigned. If the default value of 0 is used, the platform will determine the default stack size. The value assigned can be obtained by this call after the thread began execution.
|
inlinenoexcept |
|
protectednoexcept |
Internal function to set up data specific to a thread.
This function executes platform specific code to execute before actually dispatching to the thread. This function is called in the same process as the thread, not the parent process.
|
protectednoexcept |
Internal function to detach a thread.
This function executes platform specific code detach a thread.
|
protectednoexcept |
Internal function to start a thread.
This function executes platform specific code to start a thread.
|
staticnoexcept |
Internal function to dispatch to the thread.
This internal routine is used to synchronize with the main thread to ensure that the class variables are stable before execution begins. It will also capture the result code before exiting back to the operating system.
pThis | Pointer to an instance of Thread |
|
noexcept |
Startup a thread.
If a thread isn't already running, launch this thread of execution. If a thread is already running, return kErrorThreadAlreadyStarted.
If a name is passed for the name of the thread, it is copied so it's not necessary to keep the name around once this function returns.
pFunction | Pointer to the entry point to the thread |
pData | Pointer to data to pass to the thread |
pName | Pointer to a "C" string for the name of the thread |
uStackSize | Size of the stack for the thread |
|
noexcept |
|
protected |
Data pointer for the thread.
|
protected |
Pointer to the thread.
|
protected |
Name of the thread.
|
protected |
Pointer to OSThread record.
|
protected |
Memory for the thread's stack.
|
protected |
HANDLE to the thread (Windows/Xbox only)
|
protected |
Result code of the thread on exit.
|
protected |
Size of the stack allocated for the thread.
|
protected |
State of the thread, see /ref eState.
|
protected |
ThreadID assigned to this thread.