From b3f22ae85154f22532b66362a2399592d755ce33 Mon Sep 17 00:00:00 2001
From: Zebediah Figura <z.figura12@gmail.com>
Date: Fri, 8 Jun 2018 15:41:01 -0500
Subject: [PATCH 09/83] ntdll: Implement NtSetEvent().

---
 dlls/ntdll/esync.c | 21 +++++++++++++++++++++
 dlls/ntdll/esync.h |  1 +
 dlls/ntdll/sync.c  |  4 ++++
 3 files changed, 26 insertions(+)

diff --git a/dlls/ntdll/esync.c b/dlls/ntdll/esync.c
index ace2f4a45..62c56af75 100644
--- a/dlls/ntdll/esync.c
+++ b/dlls/ntdll/esync.c
@@ -282,6 +282,27 @@ NTSTATUS esync_create_event( HANDLE *handle, ACCESS_MASK access,
     return ret;
 }
 
+NTSTATUS esync_set_event( HANDLE handle, LONG *prev )
+{
+    struct event *event = esync_get_object( handle );
+    static const uint64_t value = 1;
+
+    TRACE("%p.\n", handle);
+
+    if (!event) return STATUS_INVALID_HANDLE;
+
+    if (prev)
+    {
+        FIXME("Can't write previous value.\n");
+        *prev = 1;
+    }
+
+    if (write( event->obj.fd, &value, sizeof(value) ) == -1)
+        return FILE_GetNtStatus();
+
+    return STATUS_SUCCESS;
+}
+
 #define TICKSPERSEC        10000000
 #define TICKSPERMSEC       10000
 
diff --git a/dlls/ntdll/esync.h b/dlls/ntdll/esync.h
index 32a259e39..ba1c89665 100644
--- a/dlls/ntdll/esync.h
+++ b/dlls/ntdll/esync.h
@@ -26,6 +26,7 @@ extern NTSTATUS esync_create_semaphore(HANDLE *handle, ACCESS_MASK access,
 extern NTSTATUS esync_release_semaphore( HANDLE handle, ULONG count, ULONG *prev ) DECLSPEC_HIDDEN;
 extern NTSTATUS esync_create_event( HANDLE *handle, ACCESS_MASK access,
     const OBJECT_ATTRIBUTES *attr, EVENT_TYPE type, BOOLEAN initial ) DECLSPEC_HIDDEN;
+extern NTSTATUS esync_set_event( HANDLE handle, LONG *prev ) DECLSPEC_HIDDEN;
 
 extern NTSTATUS esync_wait_objects( DWORD count, const HANDLE *handles, BOOLEAN wait_any,
                                     BOOLEAN alertable, const LARGE_INTEGER *timeout ) DECLSPEC_HIDDEN;
diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c
index 6f0e72125..1e1e381b4 100644
--- a/dlls/ntdll/sync.c
+++ b/dlls/ntdll/sync.c
@@ -417,6 +417,10 @@ NTSTATUS WINAPI NtOpenEvent( HANDLE *handle, ACCESS_MASK access, const OBJECT_AT
 NTSTATUS WINAPI NtSetEvent( HANDLE handle, LONG *prev_state )
 {
     NTSTATUS ret;
+
+    if (do_esync())
+        return esync_set_event( handle, prev_state );
+
     SERVER_START_REQ( event_op )
     {
         req->handle = wine_server_obj_handle( handle );
-- 
2.20.1

