sl@0
|
1 |
//------------------------------------------------------------------------------
|
sl@0
|
2 |
#include "Thread.h"
|
sl@0
|
3 |
//------------------------------------------------------------------------------
|
sl@0
|
4 |
Thread::Thread() : m_hThread(NULL), m_dwThreadId(0)
|
sl@0
|
5 |
{
|
sl@0
|
6 |
}
|
sl@0
|
7 |
//------------------------------------------------------------------------------
|
sl@0
|
8 |
Thread::~Thread()
|
sl@0
|
9 |
{
|
sl@0
|
10 |
if (m_hThread != NULL)
|
sl@0
|
11 |
{
|
sl@0
|
12 |
TerminateThread(m_hThread, -1);
|
sl@0
|
13 |
m_hThread = NULL;
|
sl@0
|
14 |
}
|
sl@0
|
15 |
}
|
sl@0
|
16 |
//------------------------------------------------------------------------------
|
sl@0
|
17 |
void Thread::Start()
|
sl@0
|
18 |
{
|
sl@0
|
19 |
if (m_hThread != NULL)
|
sl@0
|
20 |
return;
|
sl@0
|
21 |
m_hThread = CreateThread(
|
sl@0
|
22 |
NULL,
|
sl@0
|
23 |
0,
|
sl@0
|
24 |
Thread::ThreadProc,
|
sl@0
|
25 |
this,
|
sl@0
|
26 |
0,
|
sl@0
|
27 |
&m_dwThreadId);
|
sl@0
|
28 |
}
|
sl@0
|
29 |
//------------------------------------------------------------------------------
|
sl@0
|
30 |
void Thread::Join() const
|
sl@0
|
31 |
{
|
sl@0
|
32 |
WaitForSingleObject(m_hThread, INFINITE);
|
sl@0
|
33 |
}
|
sl@0
|
34 |
//------------------------------------------------------------------------------
|
sl@0
|
35 |
DWORD WINAPI Thread::ThreadProc(LPVOID lpParam)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
Thread* pThread = (Thread*)lpParam;
|
sl@0
|
38 |
pThread->Run();
|
sl@0
|
39 |
return 0;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
//------------------------------------------------------------------------------
|