ReactOS
0.4.16-dev-732-g2d1144a
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
16
DWORD
WINAPI
ThreadEntry
(
LPVOID
parameter)
17
{
18
ThreadData
*
p
= (
ThreadData
*) parameter;
19
20
p
->ClassPtr->Execute();
21
22
SetEvent
(
p
->hFinished);
23
return
0;
24
}
25
26
// Default constructor
27
CThread::CThread
()
28
{
29
bTerminated
=
FALSE
;
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
39
hThread
=
CreateThread
(
NULL
, 0, (
LPTHREAD_START_ROUTINE
)
ThreadEntry
, &
Data
, 0, &
dwThreadId
);
40
41
// FIXME: Do some error handling
42
assert
(
hThread
!=
NULL
);
43
}
44
45
// Default destructor
46
CThread::~CThread
()
47
{
48
if
((
hThread
!=
NULL
) && (
Data
.hFinished !=
NULL
)) {
49
if
(!
bTerminated
)
50
Terminate
();
51
WaitForSingleObject
(
Data
.hFinished,
INFINITE
);
52
CloseHandle
(
Data
.hFinished);
53
CloseHandle
(
hThread
);
54
hThread
=
NULL
;
55
}
56
}
57
58
// Execute thread code
59
void
CThread::Execute
()
60
{
61
while
(!
bTerminated
)
Sleep
(0);
62
}
63
64
// Post a message to the thread's message queue
65
BOOL
CThread::PostMessage
(
UINT
Msg
,
WPARAM
wParam
,
LPARAM
lParam
)
66
{
67
return
PostThreadMessage
(
dwThreadId
,
Msg
,
wParam
,
lParam
);
68
}
69
70
// Gracefully terminate thread
71
void
CThread::Terminate
()
72
{
73
bTerminated
=
TRUE
;
74
}
75
76
// Returns TRUE if thread is terminated, FALSE if not
77
BOOL
CThread::Terminated
()
78
{
79
return
bTerminated
;
80
}
CThread::Execute
virtual void Execute()
Definition:
thread.cpp:59
CThread::PostMessage
BOOL PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
Definition:
thread.cpp:65
CThread::hThread
HANDLE hThread
Definition:
thread.h:29
CThread::~CThread
virtual ~CThread()
Definition:
thread.cpp:46
CThread::Terminate
virtual void Terminate()
Definition:
thread.cpp:71
CThread::bTerminated
BOOL bTerminated
Definition:
thread.h:27
CThread::CThread
CThread()
Definition:
thread.cpp:27
CThread::dwThreadId
DWORD dwThreadId
Definition:
thread.h:28
CThread::Terminated
BOOL Terminated()
Definition:
thread.cpp:77
wParam
WPARAM wParam
Definition:
combotst.c:138
lParam
LPARAM lParam
Definition:
combotst.c:139
Msg
struct @1645 Msg[]
NULL
#define NULL
Definition:
types.h:112
TRUE
#define TRUE
Definition:
types.h:120
FALSE
#define FALSE
Definition:
types.h:117
CloseHandle
#define CloseHandle
Definition:
compat.h:739
CreateThread
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
assert
#define assert(x)
Definition:
debug.h:53
INFINITE
#define INFINITE
Definition:
serial.h:102
BOOL
unsigned int BOOL
Definition:
ntddk_ex.h:94
DWORD
unsigned long DWORD
Definition:
ntddk_ex.h:95
p
GLfloat GLfloat p
Definition:
glext.h:8902
void
Definition:
nsiface.idl:2307
ThreadEntry
DWORD WINAPI ThreadEntry(LPVOID parameter)
Definition:
thread.cpp:16
UINT
unsigned int UINT
Definition:
ndis.h:50
Data
Definition:
sort_test.cpp:77
ThreadData
Definition:
drwtsn32.h:24
WaitForSingleObject
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition:
synch.c:82
Sleep
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition:
synch.c:790
SetEvent
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition:
synch.c:733
thread.h
CreateEvent
#define CreateEvent
Definition:
winbase.h:3773
LPTHREAD_START_ROUTINE
DWORD(WINAPI * LPTHREAD_START_ROUTINE)(LPVOID)
Definition:
winbase.h:754
LPARAM
LONG_PTR LPARAM
Definition:
windef.h:208
WPARAM
UINT_PTR WPARAM
Definition:
windef.h:207
WINAPI
#define WINAPI
Definition:
msvc.h:6
PostThreadMessage
#define PostThreadMessage
Definition:
winuser.h:5845
modules
rosapps
applications
net
roshttpd
common
thread.cpp
Generated on Sat Feb 8 2025 06:14:41 for ReactOS by
1.9.6