forked from xNVSE/NVSE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIThread.cpp
More file actions
65 lines (52 loc) · 896 Bytes
/
Copy pathIThread.cpp
File metadata and controls
65 lines (52 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "IThread.h"
IThread::IThread()
{
mainProc = NULL;
mainProcParam = NULL;
stopRequested = false;
isRunning = false;
theThread = NULL;
threadID = 0;
}
IThread::~IThread()
{
ForceStop();
if(theThread)
{
CloseHandle(theThread);
}
}
void IThread::Start(MainProcPtr proc, void * procParam)
{
if(!isRunning)
{
isRunning = true;
stopRequested = false;
mainProc = proc;
mainProcParam = procParam;
theThread = CreateThread(NULL, 0, _ThreadProc, static_cast<IThread *>(this), 0, &threadID);
}
}
void IThread::Stop(void)
{
if(isRunning)
{
stopRequested = true;
}
}
void IThread::ForceStop(void)
{
if(isRunning)
{
TerminateThread(theThread, 0);
isRunning = false;
}
}
UInt32 IThread::_ThreadProc(void * param)
{
IThread * _this = (IThread *)param;
if(_this->mainProc)
_this->mainProc(_this->mainProcParam);
_this->isRunning = false;
return 0;
}