forked from pig4210/xlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xevent.cpp
64 lines (51 loc) · 1.07 KB
/
xevent.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
60
61
62
63
64
#include "xevent.h"
#ifdef FOR_RING0
xevent::xevent(BOOL bManualReset,BOOL bInitialState)
{
KeInitializeEvent(&kevent,
bManualReset ? NotificationEvent : SynchronizationEvent,
bInitialState == TRUE);
}
xevent::~xevent()
{
KeClearEvent(&kevent);
}
bool xevent::wait()
{
return STATUS_SUCCESS ==
KeWaitForSingleObject(&kevent,Executive,KernelMode,FALSE,nullptr);
}
void xevent::set()
{
KeSetEvent(&kevent,IO_NO_INCREMENT,FALSE);
}
void xevent::reset()
{
KeResetEvent(&kevent);
}
#else //#ifdef FOR_RING0
xevent::xevent(BOOL bManualReset,
BOOL bInitialState,
LPCTSTR lpName)
:handle(CreateEvent(nullptr,bManualReset,bInitialState,lpName))
{
;
}
xevent::~xevent()
{
CloseHandle(handle);
}
bool xevent::wait(const DWORD time)
{
const DWORD ret = WaitForSingleObject(handle,time);
return WAIT_OBJECT_0 == ret;
}
bool xevent::set()
{
return SetEvent(handle) == TRUE;
}
bool xevent::reset()
{
return ResetEvent(handle) == TRUE;
}
#endif //#ifdef FOR_RING0