forked from pig4210/xlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmutex.cpp
More file actions
44 lines (34 loc) · 706 Bytes
/
xmutex.cpp
File metadata and controls
44 lines (34 loc) · 706 Bytes
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
#include "xmutex.h"
#ifdef FOR_RING0
xmutex::xmutex()
{
KeInitializeMutex(&mutex,0);
}
xmutex::~xmutex()
{
;
}
bool xmutex::wait()
{
const NTSTATUS ret =
KeWaitForSingleObject(&mutex,Executive,KernelMode,FALSE,nullptr);
KeReleaseMutex(&mutex,FALSE);
return STATUS_SUCCESS == ret;
}
#else //#ifdef FOR_RING0
xmutex::xmutex(BOOL bInitialOwner, LPCTSTR lpName)
:handle(CreateMutex(nullptr,bInitialOwner,lpName))
{
;
}
xmutex::~xmutex()
{
CloseHandle(handle);
}
bool xmutex::wait(const DWORD time)
{
const DWORD ret = WaitForSingleObject(handle,time);
ReleaseMutex(handle);
return WAIT_OBJECT_0 == ret;
}
#endif //#ifdef FOR_RING0