class RED::Thread
Encapsulation of threading services. More...
#include <REDThreads.h>
Inherits: Object.
Public functions:
Thread ( ) | |
~Thread ( ) | |
virtual void * | As ( const RED::CID & iCID ) |
virtual const void * | As ( const RED::CID & iCID ) const |
template< class T_As > const T_As * | As ( ) const |
template< class T_As > T_As * | As ( ) |
RED_RC | Close ( ) |
HANDLE | GetHandle ( ) const |
void * | GetUserArgument ( ) const |
bool | IsRunning ( ) const |
bool | IsValid ( ) const |
RED_RC | ReturnedCode ( ) const |
RED_RC | Run ( THREAD_PRIORITY iPriority = TP_NORMAL ) |
void | Setup ( THREAD_CALLBACK iCallback, void * iCallbackArg = NULL ) |
void | StopRun ( RED_RC iRC ) |
RED_RC | WaitForTermination ( ) |
Public static functions:
static void | ChangeToAnotherThread ( ) |
static RED::CID | GetClassID ( ) |
Protected variables:
THREAD_CALLBACK | _callback |
void * | _callbackarg |
HANDLE | _handle |
RED_RC | _rc |
bool | _running |
Detailed description:
Encapsulation of threading services.
- Call RED::Thread::Setup to define a thread's callback,
- Call RED::Thread::Run to start a thread,
- The threaded method receives the RED::Thread class itself as its argument, then RED::Thread::GetUserArgument can be used to access the RED::Thread::Setup method's argument.
- Call RED::Thread::StopRun from the threaded method to end the thread,
- Call RED::Thread::WaitForTermination to wait for a thread's end from the thread launcher.
- Call RED::Thread::Close after the WaitForTermination call to close the thread.
Functions documentation
public RED::Thread::Thread | ( | ) |
Construction method.
public RED::Thread::~Thread | ( | ) |
Destruction method.
public static void RED::Thread::ChangeToAnotherThread | ( | ) |
Stops consuming time. Switch to another running thread.
This call is used to stop a thread from running right at that time. Another thread will use the processor until the caller's turn comes in again. This method is only effective on Windows where it calls SwitchToThread. It does nothing on other operating systems.
public static RED::CID RED::Thread::GetClassID | ( | ) |
Reimplements: RED::Object::GetClassID.
public virtual void * RED::Thread::As | ( | const RED::CID & | iCID | ) |
Converts the object to an instance of the given type.
Parameters:
iCID: | Requested class. |
Returns:
Reimplements: RED::Object::As.
public virtual const void * RED::Thread::As | ( | const RED::CID & | iCID | ) const |
Converts the object to an instance of the given type.
Parameters:
iCID: | Requested class. |
Returns:
Reimplements: RED::Object::As.
template< class T_As > public const T_As * RED::Thread::As | ( | ) const |
Template version of the as const method.
Simply set T to be the class you want to retrieve an interface to.
Returns:
Reimplements: RED::Object::As.
template< class T_As > public T_As * RED::Thread::As | ( | ) |
Template version of the as method.
Simply set T to be the class you want to retrieve an interface to.
Returns:
Reimplements: RED::Object::As.
public RED_RC RED::Thread::Close | ( | ) |
public HANDLE RED::Thread::GetHandle | ( | ) const |
Returns:
public void * RED::Thread::GetUserArgument | ( | ) const |
Returns:
public bool RED::Thread::IsRunning | ( | ) const |
Is the thread running?
Return true if the thread is running now. This means that the thread has not been closed.
Returns:
public bool RED::Thread::IsValid | ( | ) const |
Is the thread valid?
Returns:
public RED_RC RED::Thread::ReturnedCode | ( | ) const |
Gets the thread's return code.
Returns:
public RED_RC RED::Thread::Run | ( | THREAD_PRIORITY | iPriority = TP_NORMAL | ) |
Runs the thread.
When this method is called, the thread is run and the user callback is called with the thread being passed as an argument.
Parameters:
iPriority | optional thread priority. |
Returns:
RED_WORKFLOW_ERROR if the thread's resources are still used, and have not been released,
RED_FAIL if we have no valid callback.
public void RED::Thread::Setup | ( | THREAD_CALLBACK | iCallback, |
void * | iCallbackArg = NULL | ||
) |
Defines the thread's parameters.
Parameters:
iCallback: | pointer to the callback that will be called by the thread. |
iCallbackArg: | Optional pointer to the callback user argument. |
public void RED::Thread::StopRun | ( | RED_RC | iRC | ) |
Prepares thread exit.
This method must be called from the threaded method. It indicates that the thread will terminate after this method. Practically, the threaded method must return after this call. Note that the thread must be closed (from the launching thread) after it has returned to release all its resources.
Parameters:
iRC: | Return code value of the thread. |
public RED_RC RED::Thread::WaitForTermination | ( | ) |
Variables documentation
Callback method used at the thread's startup.
Arguments to the thread callback method.
OS-dependent handle to the thread.
Return code of a thread.
Flag indicating if the thread is runnig or not.