fix: use documented synch APIs
This commit is contained in:
parent
7958b3048f
commit
5ff23accd0
@ -4,6 +4,7 @@ project(wepoll)
|
||||
include(CMakeParseArguments)
|
||||
|
||||
link_libraries(ws2_32)
|
||||
link_libraries(synchronization)
|
||||
|
||||
if(MSVC)
|
||||
add_compile_options(/Wall /WX /wd4127 /wd4201 /wd4242 /wd4710 /wd4711 /wd4820)
|
||||
|
||||
@ -21,7 +21,7 @@ static BOOL CALLBACK init__once_callback(INIT_ONCE* once,
|
||||
|
||||
/* N.b. that initialization order matters here. */
|
||||
if (ws_global_init() < 0 || nt_global_init() < 0 ||
|
||||
reflock_global_init() < 0 || epoll_global_init() < 0)
|
||||
epoll_global_init() < 0)
|
||||
return FALSE;
|
||||
|
||||
init__done = true;
|
||||
|
||||
29
src/nt.h
29
src/nt.h
@ -63,11 +63,6 @@ typedef struct _OBJECT_ATTRIBUTES {
|
||||
#define FILE_OPEN 0x00000001UL
|
||||
#endif
|
||||
|
||||
#define KEYEDEVENT_WAIT 0x00000001UL
|
||||
#define KEYEDEVENT_WAKE 0x00000002UL
|
||||
#define KEYEDEVENT_ALL_ACCESS \
|
||||
(STANDARD_RIGHTS_REQUIRED | KEYEDEVENT_WAIT | KEYEDEVENT_WAKE)
|
||||
|
||||
#define NT_NTDLL_IMPORT_LIST(X) \
|
||||
X(NTSTATUS, \
|
||||
NTAPI, \
|
||||
@ -91,14 +86,6 @@ typedef struct _OBJECT_ATTRIBUTES {
|
||||
PVOID EaBuffer, \
|
||||
ULONG EaLength)) \
|
||||
\
|
||||
X(NTSTATUS, \
|
||||
NTAPI, \
|
||||
NtCreateKeyedEvent, \
|
||||
(PHANDLE KeyedEventHandle, \
|
||||
ACCESS_MASK DesiredAccess, \
|
||||
POBJECT_ATTRIBUTES ObjectAttributes, \
|
||||
ULONG Flags)) \
|
||||
\
|
||||
X(NTSTATUS, \
|
||||
NTAPI, \
|
||||
NtDeviceIoControlFile, \
|
||||
@ -113,22 +100,6 @@ typedef struct _OBJECT_ATTRIBUTES {
|
||||
PVOID OutputBuffer, \
|
||||
ULONG OutputBufferLength)) \
|
||||
\
|
||||
X(NTSTATUS, \
|
||||
NTAPI, \
|
||||
NtReleaseKeyedEvent, \
|
||||
(HANDLE KeyedEventHandle, \
|
||||
PVOID KeyValue, \
|
||||
BOOLEAN Alertable, \
|
||||
PLARGE_INTEGER Timeout)) \
|
||||
\
|
||||
X(NTSTATUS, \
|
||||
NTAPI, \
|
||||
NtWaitForKeyedEvent, \
|
||||
(HANDLE KeyedEventHandle, \
|
||||
PVOID KeyValue, \
|
||||
BOOLEAN Alertable, \
|
||||
PLARGE_INTEGER Timeout)) \
|
||||
\
|
||||
X(ULONG, WINAPI, RtlNtStatusToDosError, (NTSTATUS Status))
|
||||
|
||||
#define X(return_type, attributes, name, parameters) \
|
||||
|
||||
@ -15,31 +15,17 @@
|
||||
#define REFLOCK__POISON ((long) 0x300dead0UL)
|
||||
/* clang-format on */
|
||||
|
||||
static HANDLE reflock__keyed_event = NULL;
|
||||
|
||||
int reflock_global_init(void) {
|
||||
NTSTATUS status = NtCreateKeyedEvent(
|
||||
&reflock__keyed_event, KEYEDEVENT_ALL_ACCESS, NULL, 0);
|
||||
if (status != STATUS_SUCCESS)
|
||||
return_set_error(-1, RtlNtStatusToDosError(status));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reflock_init(reflock_t* reflock) {
|
||||
reflock->state = 0;
|
||||
}
|
||||
|
||||
static void reflock__signal_event(void* address) {
|
||||
NTSTATUS status =
|
||||
NtReleaseKeyedEvent(reflock__keyed_event, address, FALSE, NULL);
|
||||
if (status != STATUS_SUCCESS)
|
||||
abort();
|
||||
WakeByAddressSingle(address);
|
||||
}
|
||||
|
||||
static void reflock__await_event(void* address) {
|
||||
NTSTATUS status =
|
||||
NtWaitForKeyedEvent(reflock__keyed_event, address, FALSE, NULL);
|
||||
if (status != STATUS_SUCCESS)
|
||||
BOOL status = WaitOnAddress(address, address, sizeof(void*), INFINITE);
|
||||
if (status != TRUE)
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
@ -25,8 +25,6 @@ typedef struct reflock {
|
||||
volatile long state; /* 32-bit Interlocked APIs operate on `long` values. */
|
||||
} reflock_t;
|
||||
|
||||
WEPOLL_INTERNAL int reflock_global_init(void);
|
||||
|
||||
WEPOLL_INTERNAL void reflock_init(reflock_t* reflock);
|
||||
WEPOLL_INTERNAL void reflock_ref(reflock_t* reflock);
|
||||
WEPOLL_INTERNAL void reflock_unref(reflock_t* reflock);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user