-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcthread.cpp
More file actions
73 lines (63 loc) · 2.98 KB
/
cthread.cpp
File metadata and controls
73 lines (63 loc) · 2.98 KB
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
66
67
68
69
70
71
72
//****************************************************************************************************
//ïîäêëþ÷àåìûå áèáëèîòåêè
//****************************************************************************************************
#include "cthread.h"
//****************************************************************************************************
//ôóíêöèÿ ïîòîêà
//****************************************************************************************************
static DWORD WINAPI CThreadFunction(LPVOID ptr)
{
CThread *cThread_Ptr=reinterpret_cast<CThread*>(ptr);
cThread_Ptr->Routine(cThread_Ptr->Param);
return(EXIT_SUCCESS);
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//êîíñòðóêòîð è äåñòðóêòîð êëàññà
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//----------------------------------------------------------------------------------------------------
//êîíñòðóêòîð
//----------------------------------------------------------------------------------------------------
CThread::CThread(void* (*start_routine)(void*),void *param)
{
Create(start_routine,param);
}
//----------------------------------------------------------------------------------------------------
//êîíñòðóêòîð
//----------------------------------------------------------------------------------------------------
CThread::CThread(void)
{
hThread=INVALID_HANDLE_VALUE;
}
//----------------------------------------------------------------------------------------------------
//äåñòðóêòîð
//----------------------------------------------------------------------------------------------------
CThread::~CThread()
{
Join();
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//çàêðûòûå ôóíêöèè êëàññà
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//îòêðûòûå ôóíêöèè êëàññà
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//----------------------------------------------------------------------------------------------------
//ñîçäàòü ïîòîê
//----------------------------------------------------------------------------------------------------
void CThread::Create(void* (*start_routine)(void*),void *param)
{
if (hThread!=INVALID_HANDLE_VALUE) CloseHandle(hThread);
Routine=start_routine;
Param=param;
hThread=CreateThread(NULL,0,CThreadFunction,this,0,NULL);
}
//----------------------------------------------------------------------------------------------------
//æäàòü çàâåðøåíèÿ ïîòîêà
//----------------------------------------------------------------------------------------------------
void CThread::Join(void)
{
if (hThread==INVALID_HANDLE_VALUE) return;
WaitForSingleObject(hThread,INFINITE);
CloseHandle(hThread);
hThread=INVALID_HANDLE_VALUE;
}