Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

OW32::CThread Class Reference

Threading API Wrapper class. More...

#include <Thread.h>

Inheritance diagram for OW32::CThread:

OW32::CAsyncConnectionThread OW32::CIoCompletionThread List of all members.

Public Member Functions

 CThread (bool bAutoDelete=false)
 Constructor for a CThread object. The AutoDelete flag should be set to true if you want `delete this' called at thread exit. It defaults to false, as you almost certainly don't want this :).
virtual ~CThread ()
 Default destructor that does nothing.
virtual unsigned int Run ()=0
 The thread run function to be overriden by the derived class.
virtual BOOL InitInstance ()
 This function is called just after the thread has started.
virtual void ExitInstance ()
 This function is called just after the Run function has finished execution. You can use it to provide per-thread cleanup.
bool GetAutoDelete ()
 Check if the thread is auto-deleting.
void SetAutoDelete (bool bAutoDelete)
 Set the auto-delete flag for a thread.
BOOL Create ()
 Start up the thread.
void Close ()
 Close the encapsulated thread handle.
DWORD Suspend ()
 Suspend execution of the thread.
DWORD Resume ()
 Resume execution of the thread.
int GetPriority ()
 Get the current thread priority.
int SetPriority (int nPriority)
 Set the current thread priority.
BOOL PostMessage (UINT Msg, WPARAM wParam, LPARAM lParam)
 Post a message to the thread.
HANDLE GetHandle ()
 Return the thread handle.
DWORD GetId ()
 Return the thread Id.
BOOL GetExitCode (LPDWORD lpExitCode)
 Return the thread's exit code.
 operator HANDLE ()
 Extractor for the thread handle.
 operator DWORD ()
 Extractor for the thread Id.

Detailed Description

Threading API Wrapper class.

This class provides a wrapper around the Win32 threading API. It encapsulates a thread object, which has a handle and a thread id. To use it, derive a class from CThread and override the Run() method.

This class uses the CRT _beginthreadex to ensure that CRT data structures are properly initialised and cleaned up. For this reason, do not use ExitThread(), instead use _endthread or _endthreadex should you wish to terminate the thread. You can also simply return from the Run() method. Also note that _endthread or _endthreadex will prevent the thread from auto-deleting.


Constructor & Destructor Documentation

OW32::CThread::CThread bool  bAutoDelete = false  )  [inline]
 

Constructor for a CThread object. The AutoDelete flag should be set to true if you want `delete this' called at thread exit. It defaults to false, as you almost certainly don't want this :).

Parameters:
bAutoDelete Whether to delete the object on exit.


Member Function Documentation

void OW32::CThread::Close  )  [inline]
 

Close the encapsulated thread handle.

You can do this after thread exit to return the state of this object to the default, in case it needs to be reused.

BOOL OW32::CThread::Create  )  [inline]
 

Start up the thread.

Returns:
TRUE if the thread was created, FALSE if not

bool OW32::CThread::GetAutoDelete  )  [inline]
 

Check if the thread is auto-deleting.

Returns:
true if so, false otherwise

BOOL OW32::CThread::GetExitCode LPDWORD  lpExitCode  )  [inline]
 

Return the thread's exit code.

Returns:
TRUE if successful, FALSE otherwise
Parameters:
lpExitCode variable to receive the exit code. If the thread has not terminated, the exit code is STILL_ACTIVE.
Note: only use this for non-autodeleting threads.

HANDLE OW32::CThread::GetHandle  )  [inline]
 

Return the thread handle.

Returns:
The handle of the thread

DWORD OW32::CThread::GetId  )  [inline]
 

Return the thread Id.

Returns:
The thread Id

int OW32::CThread::GetPriority  )  [inline]
 

Get the current thread priority.

Returns:
The thread's priority

virtual BOOL OW32::CThread::InitInstance  )  [inline, virtual]
 

This function is called just after the thread has started.

Returns:
TRUE if the Run() function should be called, FALSE if not.
You can place per thread specific startup here. This is equivalent to code at the start of the Run() function, it is provided for readability of code only.

OW32::CThread::operator DWORD  )  [inline]
 

Extractor for the thread Id.

Returns:
The thread Id

OW32::CThread::operator HANDLE  )  [inline]
 

Extractor for the thread handle.

Returns:
The thread handle

BOOL OW32::CThread::PostMessage UINT  Msg,
WPARAM  wParam,
LPARAM  lParam
[inline]
 

Post a message to the thread.

Parameters:
Msg The messge to post
wParam Misnamed arbitrary data #1
lParam Arbitrary data #2

DWORD OW32::CThread::Resume  )  [inline]
 

Resume execution of the thread.

Returns:
The current suspend count, or (DWORD)-1 on error

virtual unsigned int OW32::CThread::Run  )  [pure virtual]
 

The thread run function to be overriden by the derived class.

Returns:
The thread exit code.
You must override this - it is pure virtual.

Implemented in OW32::CAsyncConnectionThread, and OW32::CIoCompletionThread.

void OW32::CThread::SetAutoDelete bool  bAutoDelete  )  [inline]
 

Set the auto-delete flag for a thread.

Parameters:
bAutoDelete The new value of the auto-delete flag.
Caution: You should call this function before calling Create. If not, then the thread may have exited before you have called this method.

int OW32::CThread::SetPriority int  nPriority  )  [inline]
 

Set the current thread priority.

Parameters:
nPriority The new priority
Returns:
0 on error, anything else on success (!)

DWORD OW32::CThread::Suspend  )  [inline]
 

Suspend execution of the thread.

Returns:
The current suspend count, or (DWORD)-1 on error


The documentation for this class was generated from the following file:
Generated on Sun Jun 5 01:29:29 2005 for OW32 by  doxygen 1.3.9.1