ReactOS  0.4.13-dev-99-g7e18b6d
thread.cpp
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS HTTP Daemon
4  * FILE: thread.cpp
5  * PURPOSE: Generic thread class
6  * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  * REVISIONS:
8  * CSH 01/09/2000 Created
9  */
10 #include <debug.h>
11 #include <assert.h>
12 #include <windows.h>
13 #include <thread.h>
14 
15 // This is the thread entry code
17 {
18  ThreadData *p = (ThreadData*) parameter;
19 
20  p->ClassPtr->Execute();
21 
22  SetEvent(p->hFinished);
23  return 0;
24 }
25 
26 // Default constructor
28 {
30  // Points to the class that is executed within thread
31  Data.ClassPtr = this;
32  // Create synchronization event
33  Data.hFinished = CreateEvent(NULL, TRUE, FALSE, NULL);
34 
35  // FIXME: Do some error handling
36  assert(Data.hFinished != NULL);
37 
38  // Create thread
40 
41  // FIXME: Do some error handling
42  assert(hThread != NULL);
43 }
44 
45 // Default destructor
47 {
48  if ((hThread != NULL) && (Data.hFinished != NULL)) {
49  if (!bTerminated)
50  Terminate();
51  WaitForSingleObject(Data.hFinished, INFINITE);
52  CloseHandle(Data.hFinished);
54  hThread = NULL;
55  }
56 }
57 
58 // Execute thread code
60 {
61  while (!bTerminated) Sleep(0);
62 }
63 
64 // Post a message to the thread's message queue
66 {
68 }
69 
70 // Gracefully terminate thread
72 {
73  bTerminated = TRUE;
74 }
75 
76 // Returns TRUE if thread is terminated, FALSE if not
78 {
79  return bTerminated;
80 }
#define CreateEvent
Definition: winbase.h:3562
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:707
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define assert(x)
Definition: debug.h:53
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
struct @1567 Msg[]
UINT_PTR WPARAM
Definition: windef.h:207
WPARAM wParam
Definition: combotst.c:138
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
unsigned int BOOL
Definition: ntddk_ex.h:94
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:112
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
BOOL bTerminated
Definition: thread.h:27
#define PostThreadMessage
Definition: winuser.h:5699
#define WINAPI
Definition: msvc.h:8
virtual ~CThread()
Definition: thread.cpp:46
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Terminated()
Definition: thread.cpp:77
HANDLE hThread
Definition: thread.h:29
DWORD WINAPI ThreadEntry(LPVOID parameter)
Definition: thread.cpp:16
unsigned int UINT
Definition: ndis.h:50
CThread()
Definition: thread.cpp:27
virtual void Execute()
Definition: thread.cpp:59
virtual void Terminate()
Definition: thread.cpp:71
BOOL PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: thread.cpp:65
GLfloat GLfloat p
Definition: glext.h:8902
#define INFINITE
Definition: serial.h:102
DWORD dwThreadId
Definition: thread.h:28
LPARAM lParam
Definition: combotst.c:139