2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS HTTP Daemon
5 * PURPOSE: Generic thread class
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * CSH 01/09/2000 Created
15 // This is the thread entry code
16 DWORD WINAPI ThreadEntry(LPVOID parameter)
18 ThreadData *p = (ThreadData*) parameter;
20 p->ClassPtr->Execute();
22 SetEvent(p->hFinished);
26 // Default constructor
30 // Points to the class that is executed within thread
32 // Create synchronization event
33 Data.hFinished = CreateEvent(NULL, TRUE, FALSE, NULL);
35 // FIXME: Do some error handling
36 assert(Data.hFinished != NULL);
39 hThread = CreateThread(NULL, 0, ThreadEntry, &Data, 0, &dwThreadId);
41 // FIXME: Do some error handling
42 assert(hThread != NULL);
48 if ((hThread != NULL) && (Data.hFinished != NULL)) {
51 WaitForSingleObject(Data.hFinished, INFINITE);
52 CloseHandle(Data.hFinished);
58 // Execute thread code
59 void CThread::Execute()
61 while (!bTerminated) Sleep(0);
64 // Post a message to the thread's message queue
65 BOOL CThread::PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
67 return PostThreadMessage(dwThreadId, Msg, wParam, lParam);
70 // Gracefully terminate thread
71 void CThread::Terminate()
76 // Returns TRUE if thread is terminated, FALSE if not
77 BOOL CThread::Terminated()