class CoreExport ThreadEngine
{
public:
+ /** Per-thread state, present in each Thread object, managed by the ThreadEngine
+ */
+ struct ThreadState
+ {
+ HANDLE handle;
+ };
+
static DWORD WINAPI Entry(void* parameter);
/** Create a new thread. This takes an already allocated
void Stop(Thread* thread);
};
-class CoreExport ThreadData
-{
- public:
- HANDLE handle;
-};
-
/** The Mutex class represents a mutex, which can be used to keep threads
* properly synchronised. Use mutexes sparingly, as they are a good source
* of thread deadlocks etc, and should be avoided except where absolutely
}
};
-class ThreadQueueData
+class ThreadQueueData : public Mutex
{
- CRITICAL_SECTION mutex;
HANDLE event;
public:
ThreadQueueData()
event = CreateEvent(NULL, false, false, NULL);
if (event == NULL)
throw CoreException("CreateEvent() failed in ThreadQueueData::ThreadQueueData()!");
- InitializeCriticalSection(&mutex);
}
~ThreadQueueData()
{
CloseHandle(event);
- DeleteCriticalSection(&mutex);
- }
-
- void Lock()
- {
- EnterCriticalSection(&mutex);
- }
-
- void Unlock()
- {
- LeaveCriticalSection(&mutex);
}
void Wakeup()
void Wait()
{
- LeaveCriticalSection(&mutex);
+ Unlock();
WaitForSingleObject(event, INFINITE);
- EnterCriticalSection(&mutex);
+ Lock();
}
};