Game Development Reference
In-Depth Information
GCC_ERROR(
Could not create thread!
);
Fail();
return;
}
SetThreadPriority(m_hThread, m_ThreadPriority);
}
DWORD WINAPI RealtimeProcess::ThreadProc( LPVOID lpParam )
{
RealtimeProcess *proc = static_cast<RealtimeProcess *>(lpParam);
proc->VThreadProc();
return TRUE;
}
Note the thread parameter in the call to CreateThread() ? It is a pointer to the
static ThreadProc method, which casts the thread parameter back to a pointer to
the process instance. All the base classes must do is define the VThreadProc mem-
ber function.
The only new call you haven
t seen yet is the call to SetThreadPriority() , where
you tell Windows how much processor time to allocate to this thread.
Here
'
'
s how you would create a real-time process to increment a global integer, just
like you saw earlier:
class ProtectedProcess : public RealtimeProcess
{
public:
static DWORD g_ProtectedTotal;
static CRITICAL_SECTION g_criticalSection;
DWORD m_MaxLoops;
ProtectedProcess(DWORD maxLoops)
: RealtimeProcess(ThreadProc)
{ m_MaxLoops = maxLoops; }
virtual void VThreadProc(void);
};
DWORD ProtectedProcess::g_ProtectedTotal = 0;
CriticalSection ProtectedProcess::g_criticalSection;
void ProtectedProcess::VThreadProc(void)
{
DWORD dwCount = 0;
while( dwCount < m_MaxLoops )
Search WWH ::




Custom Search