#include <cascade/interthread/CascadeThread.h>
Inheritance diagram for CascadeThread:
Public Member Functions | |
CascadeThread () | |
virtual | ~CascadeThread () |
bool | Start (bool bDetached=false) |
bool | WaitUntilFinished () |
bool | Detach () |
u32 | GetThreadID () |
void | SetName (const char *pName) |
void | GetName (char *pBuff, u32 nBuffLen) |
bool | SetRealtimePriority (int nPriority) |
bool | GetRealtimePriority (int &nRealtimePriorityToSet) |
bool | SetNonRealtime () |
bool | IsRealtimeThread () |
deterimines whether or not a thread is a real-time thread | |
Static Public Member Functions | |
static void | Sleep (u32 nMilliseconds) |
static u32 | GetCurrentThreadID () |
static void | GetValidRealtimePriorityRange (int &lowest, int &highest) |
static bool | IsValidRealtimePriority (int nPriority) |
Protected Member Functions | |
virtual void | ThreadProc ()=0 |
CascadeThread provides easy to use access to posix threads.
|
the default constructor - lightweight This default constructor is lightweight. |
|
destructor The destructor.
|
|
Detaches a thread Detach() detaches the thread, meaning that it will delete itself upon completion. This is a very dangerous function. You must not reference or cause this thread object to be referenced once you call Detach(). Once Detach() is called the thread could delete itself at any point in time. You may not call WaitUntilFinished() or any other function. (Don't reference this thread after calling this function!!!)
|
|
gets the thread id of the calling thread. GetCurrentThreadID() gets the thread ID of the calling thread, (not this). Note that GetCurrentThreadID() is static.
|
|
gets the name of the thread GetName() fills *pBuff with the name of the thread.
|
|
gets the realtime thread priority GetRealtimePriority() sets nRealtimePriorityToSet with the current real time priority of the thread, returning true if successful, false if the thread is not real-time scheduled. If GetRealtimePriority() returns false, nRealtimePriorityToSet is left untouched.
|
|
gets the thread id of this thread. GetThreadID() gets the thread ID of the this thread.
|
|
gets the valid range for real-time thread priorities GetValidRealtimePriorityRange() sets lowest and highest with the lowest and highest priorities available for setting with SetRealtimePriority(). Note that lowest may be > highest, indicating the lower the number the higher the priority.
|
|
deterimines whether or not a thread is a real-time thread
|
|
determines whether or not a priority is a valid real-time priority IsValidRealtimePriority() returns true if nPriority represents a valid realtime thread priority, false otherwise - it uses GetValidRealtimePriorityRange automatically taking into account proper range ordering
|
|
sets the name for the thread SetName() sets the name of the thread. This name is associated with the thread, but not otherwise used. It can be useful for debugging purposes.
|
|
sets the thread to have non-realtime priority SetNonRealtime() may be used to turn a real-time thread into a non-real time thread. It returns true if successful, false otherwise.
|
|
sets the realtime thread priority SetRealtimePriority() sets the scheduling policy for this thread to use real-time scheduling (currently SCHED_RR) and sets the priority of the thread to nPriority returning true if successful or false otherwise. Only processes with SuperUser priviliges can set a thread to have a realtime priority. nPriority must be in the range described by GetValidRealtimePriorityRange(). The new priority will not take effect until the thread is started. If the thread is already running, the new priority will take effect immediately. Failure (for non super-users) occurs immediately on running threads, and only when Start() is called for non-started threads.
|
|
causes the calling thread to sleep Sleep() causes the calling thread, (not this) to sleep for nMilliseconds. Note that Sleep() is static.
|
|
starts the thread Start() starts the thread returning true if successful, false otherwise. if the thread is already running, Start() will return true! By default a thread is not detached, it can be joined with a call to WaitUntilFinished(). If a thread is detached, this must NO LONGER be used after Start(true) is called. the this pointer will be auto-deleted if the thread is detached. WaitUntilFinished() must not be called on detached threads. Start threads like this: NON-DETACHED (DEFAULT): { CascadeThread thread; thread.Start(); ... thread.WaitUntilFinished(); } // must WaitUntilFinished() before destruction! or { CascadeThread * pThread = new CascadeThread; pThread->Start(); pThread->WaitUntilFinished(); delete pThread; }
DETACHED: (new CascadeThread)->Start(true); or CascadeThread * pThread = new CascadeThread; pThread->Start(true); // do not use pThread any more after Start(true)
|
|
the entry point to your thread This is the most important function in this class. It is the thread entry point and must be overridden by subclasses to gain control. |
|
waits until a thread is finished WaitUntilFinished() causes the calling thread to block until this thread finishes. WaitUntilFinished() returns true if successful, false if unsuccessful. There are two cases where WaitUntilFinished may return false. Both cases are illegal case 1 - a thread tries to wait on itself. case 2 - two distinct other threads call WaitUntilFinished on the same thread at the same time (only one thread is allowed to wait for another thread to finish at a time).
|