The Nebula Device 3: Jobs::TPWorkerThread Class Reference

The Nebula Device 3

Jobs::TPWorkerThread Class Reference

#include <tpworkerthread.h>

Inheritance diagram for Jobs::TPWorkerThread:

Threading::Thread Win360::Win360Thread Core::RefCounted

Detailed Description

The worker thread class of the thread-pool job system.

(C) 2009 Radon Labs GmbH

Public Types

enum  Priority
 thread priorities

Public Member Functions

 TPWorkerThread ()
 constructor
virtual ~TPWorkerThread ()
 destructor
virtual void EmitWakeupSignal ()
 called if thread needs a wakeup call before stopping
virtual void DoWork ()
 this method runs in the thread context
void Stop ()
 request threading code to stop, returns when thread has actually finished
void PushJobCommand (const TPJobCommand &cmd)
 push a job command onto the job queue
void SetPriority (Priority p)
 set the thread priority
Priority GetPriority () const
 get the thread priority
void SetCoreId (System::Cpu::CoreId coreId)
 set cpu core on which the thread should be running
System::Cpu::CoreId GetCoreId () const
 get the cpu core on which the thread should be running
void SetStackSize (SizeT s)
 set stack size in bytes (default is 4 KByte)
SizeT GetStackSize () const
 get stack size
void SetName (const Util::String &n)
 set thread name
const Util::StringGetName () const
 get thread name
void Start ()
 start executing the thread code, returns when thread has actually started
bool IsRunning () const
 return true if thread has been started
int GetRefCount () const
 get the current refcount
void AddRef ()
 increment refcount by one
void Release ()
 decrement refcount and destroy object if refcount is zero
bool IsInstanceOf (const Rtti &rtti) const
 return true if this object is instance of given class
bool IsInstanceOf (const Util::String &className) const
 return true if this object is instance of given class by string
bool IsInstanceOf (const Util::FourCC &classFourCC) const
 return true if this object is instance of given class by fourcc
bool IsA (const Rtti &rtti) const
 return true if this object is instance of given class, or a derived class
bool IsA (const Util::String &rttiName) const
 return true if this object is instance of given class, or a derived class, by string
bool IsA (const Util::FourCC &rttiFourCC) const
 return true if this object is instance of given class, or a derived class, by fourcc
const Util::StringGetClassName () const
 get the class name
Util::FourCC GetClassFourCC () const
 get the class FourCC code

Static Public Member Functions

static void YieldThread ()
 yield the thread (gives up current time slice)
static void SetMyThreadName (const char *n)
 set thread name from within thread context
static const char * GetMyThreadName ()
 obtain name of thread from within thread context
static Threading::ThreadId GetMyThreadId ()
 get the thread ID of this thread
static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA3_DEBUG builds only!)

Protected Member Functions

bool ThreadStopRequested () const
 check if stop is requested, call from DoWork() to see if the thread proc should quit

Member Function Documentation

void Win360::Win360Thread::SetName ( const Util::String n  )  [inline, inherited]

set thread name

Set the thread's name. To obtain the current thread's name from anywhere in the thread's execution context, call the static method Thread::GetMyThreadName().

const Util::String & Win360::Win360Thread::GetName (  )  const [inline, inherited]

get thread name

Get the thread's name. This is the vanilla method which returns the name member. To obtain the current thread's name from anywhere in the thread's execution context, call the static method Thread::GetMyThreadName().

void Win360::Win360Thread::Start (  )  [inherited]

start executing the thread code, returns when thread has actually started

Start the thread, this creates a Win32 thread and calls the static ThreadProc, which in turn calls the virtual DoWork() class of this object. The method waits for the thread to start and then returns.

bool Win360::Win360Thread::IsRunning (  )  const [inherited]

return true if thread has been started

Returns true if the thread is currently running.

void Win360::Win360Thread::YieldThread (  )  [static, inherited]

yield the thread (gives up current time slice)

The yield function is empty on Win32 and Xbox360.

void Win360::Win360Thread::SetMyThreadName ( const char *  n  )  [static, inherited]

set thread name from within thread context

Static method which sets the name of this thread. This is called from within ThreadProc. The string pointed to must remain valid until the thread is terminated!

const char * Win360::Win360Thread::GetMyThreadName (  )  [static, inherited]

obtain name of thread from within thread context

Static method to obtain the current thread name from anywhere in the thread's code.

Threading::ThreadId Win360::Win360Thread::GetMyThreadId (  )  [static, inherited]

get the thread ID of this thread

Static method which returns the ThreadId of this thread.

bool Win360::Win360Thread::ThreadStopRequested (  )  const [inline, protected, inherited]

check if stop is requested, call from DoWork() to see if the thread proc should quit

If the derived DoWork() method is running in a loop it must regularly check if the process wants the thread to terminate by calling ThreadStopRequested() and simply return if the result is true. This will cause the thread to shut down.

int Core::RefCounted::GetRefCount (  )  const [inline, inherited]

get the current refcount

Return the current refcount of the object.

void Core::RefCounted::AddRef (  )  [inline, inherited]

increment refcount by one

Increment the refcount of the object.

void Core::RefCounted::Release (  )  [inline, inherited]

decrement refcount and destroy object if refcount is zero

Decrement the refcount and destroy object if refcount is zero.

const Util::String & Core::RefCounted::GetClassName (  )  const [inline, inherited]

get the class name

Get the class name of the object.

Util::FourCC Core::RefCounted::GetClassFourCC (  )  const [inline, inherited]

get the class FourCC code

Get the class FourCC of the object.

void Core::RefCounted::DumpRefCountingLeaks (  )  [static, inherited]

dump refcounting leaks, call at end of application (NEBULA3_DEBUG builds only!)

This method should be called as the very last before an application exits.