Apply changes from https://github.com/dotnet/runtime/commit/eb1756e97d23df13bc6fe798e...
[mono-project.git] / mono / metadata / w32event-win32.c
blobf51d75ba7ded043e8b96412f2b0c3110980731a9
1 /**
2 * \file
3 * Runtime support for managed Event on Win32
5 * Author:
6 * Ludovic Henry (luhenry@microsoft.com)
8 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
9 */
11 #include "w32event.h"
13 #include <windows.h>
14 #include <winbase.h>
15 #include <mono/metadata/handle.h>
16 #include <mono/utils/mono-error-internals.h>
17 #include "icall-decl.h"
19 void
20 mono_w32event_init (void)
24 gpointer
25 mono_w32event_create (gboolean manual, gboolean initial)
27 return CreateEvent (NULL, manual, initial, NULL);
30 gboolean
31 mono_w32event_close (gpointer handle)
33 return CloseHandle (handle);
36 void
37 mono_w32event_set (gpointer handle)
39 SetEvent (handle);
42 void
43 mono_w32event_reset (gpointer handle)
45 ResetEvent (handle);
48 gpointer
49 ves_icall_System_Threading_Events_CreateEvent_icall (MonoBoolean manual, MonoBoolean initial,
50 const gunichar2 *name, gint32 name_length, gint32 *win32error, MonoError *error)
52 gpointer event;
54 MONO_ENTER_GC_SAFE;
55 event = CreateEventW (NULL, manual, initial, name);
56 *win32error = GetLastError ();
57 MONO_EXIT_GC_SAFE;
59 return event;
62 gboolean
63 ves_icall_System_Threading_Events_SetEvent_internal (gpointer handle)
65 return SetEvent (handle);
68 gboolean
69 ves_icall_System_Threading_Events_ResetEvent_internal (gpointer handle)
71 return ResetEvent (handle);
74 void
75 ves_icall_System_Threading_Events_CloseEvent_internal (gpointer handle)
77 CloseHandle (handle);
80 gpointer
81 ves_icall_System_Threading_Events_OpenEvent_icall (const gunichar2 *name, gint32 name_length,
82 gint32 rights, gint32 *win32error, MonoError *error)
84 gpointer handle;
86 *win32error = ERROR_SUCCESS;
88 MONO_ENTER_GC_SAFE;
89 handle = OpenEventW (rights, FALSE, name);
90 if (!handle)
91 *win32error = GetLastError ();
92 MONO_EXIT_GC_SAFE;
94 return handle;