diff --git a/CMakeLists.txt b/CMakeLists.txt index dfc13b7..e482540 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/init.c b/src/init.c index 04f72bc..78b3aab 100644 --- a/src/init.c +++ b/src/init.c @@ -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; diff --git a/src/nt.h b/src/nt.h index 4e66548..caf4865 100644 --- a/src/nt.h +++ b/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) \ diff --git a/src/reflock.c b/src/reflock.c index 60a96b5..76af8bb 100644 --- a/src/reflock.c +++ b/src/reflock.c @@ -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(); } diff --git a/src/reflock.h b/src/reflock.h index 7f6d5a6..a3d276e 100644 --- a/src/reflock.h +++ b/src/reflock.h @@ -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);