nux-0.9.48

nux::NThread Class Reference

#include <NuxCore/ThreadGNU.h>

Inheritance diagram for nux::NThread:
nux::AbstractThread nux::SystemThread nux::WindowThread

Data Structures

class  NThreadContext

Public Member Functions

 NThread ()
 NThread (ThreadRoutineFunc lpExternalRoutine)
virtual ~NThread ()
virtual ThreadState Start (void *arg=NULL)
virtual ThreadState Stop (bool bForceKill=false)
ThreadState Suspend ()
ThreadState Resume ()
ThreadState ResumeStart ()
ThreadState ResumeExit ()
t_u32 GetExitCode () const
void Attach (ThreadRoutineFunc lpThreadFunc)
void Detach (void)
t_u32 GetThreadId ()
ThreadState GetThreadState () const
void SetThreadState (ThreadState state)

Protected Member Functions

virtual t_u32 Run (void *)
virtual bool ThreadCtor ()
virtual bool ThreadDtor ()

Static Protected Member Functions

static void * EntryPoint (void *)

Protected Attributes

volatile ThreadState m_ThreadState
NThreadContext m_ThreadCtx
ThreadRoutineFunc m_pThreadFunc

Constructor & Destructor Documentation

nux::NThread::NThread ( )

Info: Default Constructor

nux::NThread::NThread ( ThreadRoutineFunc  lpExternalRoutine)

Info: Plug Constructor

Use this to migrate/port existing worker threads to objects immediately Although you lose the benefits of ThreadCTOR and ThreadDTOR.

virtual nux::NThread::~NThread ( ) [virtual]

Info: Default Destructor

I think it is wise to destroy the thread even if it is running, when the main thread reaches here.


Member Function Documentation

void nux::NThread::Attach ( ThreadRoutineFunc  lpThreadFunc) [inline]

Info: Attaches a Thread Function

Used primarily for porting but can serve in developing generic thread objects

References m_pThreadFunc.

void nux::NThread::Detach ( void  ) [inline]

Info: Detaches the Attached Thread Function

Detaches the Attached Thread Function, If any. by resetting the thread function pointer to EntryPoint1

References EntryPoint(), and m_pThreadFunc.

static void* nux::NThread::EntryPoint ( void *  ) [static, protected]

Info: DONT override this method.

This function is like a standard template. Override if you are sure of what you are doing.

In C++ the entry function of a thread cannot be a normal member function of a class. However, it can be a static member function of a class. This is what we will use as the entry point. There is a gotcha here though. Static member functions do not have access to the this pointer of a C++ object. They can only access static data. Fortunately, there is way to do it. Thread entry point functions take a void * as a parameter so that the caller can typecast any data and pass in to the thread. We will use this to pass this to the static function. The static function will then typecast the void * and use it to call a non static member function

Referenced by Detach().

t_u32 nux::NThread::GetExitCode ( ) const

Info: Starts the thread.

This function starts the thread pointed by m_pThreadFunc with default attributes

t_u32 nux::NThread::GetThreadId ( )
ThreadState nux::NThread::GetThreadState ( ) const
ThreadState nux::NThread::Resume ( )
ThreadState nux::NThread::ResumeExit ( )
ThreadState nux::NThread::ResumeStart ( )
virtual t_u32 nux::NThread::Run ( void *  ) [inline, protected, virtual]

Info: Override this method.

This function should contain the body/code of your thread. Notice the signature is similar to that of any worker thread function except for the calling convention.

Reimplemented in nux::AbstractThread, nux::SystemThread, and nux::WindowThread.

References m_ThreadCtx.

void nux::NThread::SetThreadState ( ThreadState  state)
virtual ThreadState nux::NThread::Start ( void *  arg = NULL) [virtual]

Info: Starts the thread.

This function starts the thread pointed by m_pThreadFunc with default attributes

Reimplemented in nux::SystemThread, and nux::WindowThread.

virtual ThreadState nux::NThread::Stop ( bool  bForceKill = false) [virtual]

Info: Stops the thread.

This function stops the current thread. We can force kill a thread which results in a TerminateThread.

ThreadState nux::NThread::Suspend ( )
virtual bool nux::NThread::ThreadCtor ( ) [inline, protected, virtual]

Info: Constructor-like function.

Will be called by EntryPoint before executing the thread body. Override this function to provide your extra initialization.

NOTE: do not confuse it with the classes constructor

Returns:
TRUE if the thread can continue running the program. If FALSE is returned, the thread won't execute the main body Run() and will exit without calling ThreadDtor.

Reimplemented in nux::SystemThread, and nux::WindowThread.

virtual bool nux::NThread::ThreadDtor ( ) [inline, protected, virtual]

Info: Destructor-like function.

Will be called by EntryPoint after executing the thread body. Override this function to provide your extra destruction.

NOTE: do not confuse it with the classes constructor

Returns:
TRUE if this function executed without problems.

Reimplemented in nux::SystemThread, and nux::WindowThread.


Field Documentation

NThreadContext nux::NThread::m_ThreadCtx [protected]

Attributes Section

Info: Members of NThread

Referenced by Run().


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