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_RCClose ( )
HANDLEGetHandle ( ) const
void *GetUserArgument ( ) const
boolIsRunning ( ) const
boolIsValid ( ) const
RED_RCReturnedCode ( ) const
RED_RCRun ( THREAD_PRIORITY iPriority = TP_NORMAL )
voidSetup ( THREAD_CALLBACK iCallback, void * iCallbackArg = NULL )
voidStopRun ( RED_RC iRC )
RED_RCWaitForTermination ( )

Public static functions:

static voidChangeToAnotherThread ( )
static RED::CIDGetClassID ( )

Protected variables:

THREAD_CALLBACK_callback
void *_callbackarg
HANDLE_handle
RED_RC_rc
bool_running

Detailed description:

Encapsulation of threading services.

Functions documentation

Construction method.

Destruction method.

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 virtual void * RED::Thread::As(const RED::CID &iCID)

Converts the object to an instance of the given type.

Parameters:

iCID:Requested class.

Returns:

An object pointer of the given class on success, NULL otherwise.

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:

An object pointer of the given class on success, NULL otherwise.

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:

A pointer to a const instance of class T on success, NULL otherwise.

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:

A pointer to an instance of class T on success, NULL otherwise.

Reimplements: RED::Object::As.

Releases threading resources.

This method must be called before the thread can be run again. The thread's resources are released. The thread must have ended before this method can be called.

Returns:

RED_OK on success,
RED_FAIL otherwise.
public HANDLE RED::Thread::GetHandle() const

Returns:

the WINDOWS thread handle.
public void * RED::Thread::GetUserArgument() const

Returns:

The address of the user argument.
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:

true if the thread is running false otherwise.
public bool RED::Thread::IsValid() const

Is the thread valid?

Returns:

true if we're between a Run and a Close. This does not indicate whether the thread has exit or not.

Gets the thread's return code.

Returns:

The current thread's return code.

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:

iPriorityoptional thread priority.

Returns:

RED_OK on success,
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_CALLBACKiCallback,
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.

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.

Blocks the caller until the given thread terminates.

Returns:

RED_OK on success,
RED_FAIL if the wait ended in error. This may be related to a thread that has not been terminated using REDThread::Exit.

Variables documentation

protected THREAD_CALLBACK RED::Thread::_callback

Callback method used at the thread's startup.

protected void * RED::Thread::_callbackarg

Arguments to the thread callback method.

protected HANDLE RED::Thread::_handle

OS-dependent handle to the thread.

Return code of a thread.

protected bool RED::Thread::_running

Flag indicating if the thread is runnig or not.