-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompleteEvent.cpp
59 lines (48 loc) · 1.07 KB
/
CompleteEvent.cpp
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
#include "stdafx.h"
#include "CompleteEvent.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#endif
CompleteEvent::CompleteEvent() : m_CompletePtr( CreateEvent( NULL , TRUE , FALSE , NULL ) ) {}
void CompleteEvent::Init()
{
if ( m_CompletePtr.Get() )
{
HANDLE h = m_CompletePtr.Reset( NULL );
SetEvent( h );
CloseHandle( h );
}
m_CompletePtr.Reset( CreateEvent( NULL , TRUE , FALSE , NULL ) );
}
BOOL CompleteEvent::IsDone()
{
return WaitComplete( 0 );
}
BOOL CompleteEvent::WaitComplete( DWORD WaitTick )
{
return WaitForSingleObject( m_CompletePtr.Get() , WaitTick ) == WAIT_OBJECT_0;
}
BOOL CompleteEvent::Signal()
{
return SetEvent( m_CompletePtr.Get() );
}
//-----------------------------------------------------------------
CS::CS()
{
InitializeCriticalSectionAndSpinCount( &_cs , 3000 );
m_bInit = TRUE;
}
CS::CS( CS&& r )
{
_cs = r._cs;
m_bInit = TRUE;
r.m_bInit = FALSE;
}
CS::~CS()
{
if ( !m_bInit ) return;
DeleteCriticalSection( &_cs );
}
//-----------------------------------------------------------------