-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCcpThreadClass.cpp
More file actions
88 lines (74 loc) · 1.28 KB
/
CcpThreadClass.cpp
File metadata and controls
88 lines (74 loc) · 1.28 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright © 2015 CCP ehf.
#include "include/CcpThread.h"
// CcpThread implementation cannot reside in CcpThread.cpp file because we
// cannot mix BLUEIMPORT and statically-linked functions in a single cpp file.
#if defined(_MSC_VER) && _MSC_VER <= 1700
CcpThread::CcpThread()
:m_thread( nullptr ),
m_id( 0 )
{
}
CcpThread::CcpThread( CcpThread&& other )
:m_thread( other.m_thread ),
m_id( other.m_id )
{
other.m_thread = nullptr;
other.m_id = 0;
}
CcpThread::~CcpThread()
{
if( joinable() )
{
std::terminate();
}
}
CcpThread& CcpThread::operator=( CcpThread&& other )
{
if( joinable() )
{
std::terminate();
}
if( &other == this )
{
return *this;
}
m_thread = other.m_thread;
m_id = other.m_id;
other.m_thread = nullptr;
other.m_id = 0;
return *this;
}
bool CcpThread::joinable() const
{
return m_thread != nullptr;
}
DWORD CcpThread::get_id() const
{
return m_id;
}
HANDLE CcpThread::native_handle()
{
return m_thread;
}
void CcpThread::join()
{
if( joinable() )
{
WaitForSingleObject( m_thread, INFINITE );
CloseHandle( m_thread );
m_thread = nullptr;
}
}
void CcpThread::detach()
{
if( joinable() )
{
CloseHandle( m_thread );
m_thread = nullptr;
}
}
void CcpThread::swap( CcpThread& other )
{
std::swap( m_thread, other.m_thread );
}
#endif