ReactOS 0.4.15-dev-8119-g4fb2fdb
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
43}
44
45// Default destructor
47{
48 if ((hThread != NULL) && (Data.hFinished != NULL)) {
49 if (!bTerminated)
50 Terminate();
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{
74}
75
76// Returns TRUE if thread is terminated, FALSE if not
78{
79 return bTerminated;
80}
virtual void Execute()
Definition: thread.cpp:59
BOOL PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: thread.cpp:65
HANDLE hThread
Definition: thread.h:29
virtual ~CThread()
Definition: thread.cpp:46
virtual void Terminate()
Definition: thread.cpp:71
BOOL bTerminated
Definition: thread.h:27
CThread()
Definition: thread.cpp:27
DWORD dwThreadId
Definition: thread.h:28
BOOL Terminated()
Definition: thread.cpp:77
struct @1637 Msg[]
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
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:137
#define assert(x)
Definition: debug.h:53
#define INFINITE
Definition: serial.h:102
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLfloat GLfloat p
Definition: glext.h:8902
unsigned int UINT
Definition: ndis.h:50
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
DWORD WINAPI ThreadEntry(LPVOID parameter)
Definition: thread.cpp:16
#define CreateEvent
Definition: winbase.h:3748
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition: winbase.h:729
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define WINAPI
Definition: msvc.h:6
#define PostThreadMessage
Definition: winuser.h:5833