[io-layer] Extract error (#4279)
[mono.git] / mono / metadata / w32event-win32.c
1 /*
2  * w32event-win32.c: Runtime support for managed Event on Win32
3  *
4  * Author:
5  *      Ludovic Henry (luhenry@microsoft.com)
6  *
7  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
8  */
9
10 #include "w32event.h"
11
12 #include <windows.h>
13 #include <winbase.h>
14
15 void
16 mono_w32event_init (void)
17 {
18 }
19
20 gpointer
21 mono_w32event_create (gboolean manual, gboolean initial)
22 {
23         return CreateEvent (NULL, manual, initial, NULL);
24 }
25
26 gboolean
27 mono_w32event_close (gpointer handle)
28 {
29         return CloseHandle (handle);
30 }
31
32 void
33 mono_w32event_set (gpointer handle)
34 {
35         SetEvent (handle);
36 }
37
38 void
39 mono_w32event_reset (gpointer handle)
40 {
41         ResetEvent (handle);
42 }
43
44 gpointer
45 ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoString *name, gint32 *error)
46 {
47         gpointer event;
48
49         event = CreateEvent (NULL, manual, initial, name ? mono_string_chars (name) : NULL);
50
51         *error = GetLastError ();
52
53         return event;
54 }
55
56 gboolean
57 ves_icall_System_Threading_Events_SetEvent_internal (gpointer handle)
58 {
59         return SetEvent (handle);
60 }
61
62 gboolean
63 ves_icall_System_Threading_Events_ResetEvent_internal (gpointer handle)
64 {
65         return ResetEvent (handle);
66 }
67
68 void
69 ves_icall_System_Threading_Events_CloseEvent_internal (gpointer handle)
70 {
71         CloseHandle (handle);
72 }
73
74 gpointer
75 ves_icall_System_Threading_Events_OpenEvent_internal (MonoString *name, gint32 rights, gint32 *error)
76 {
77         gpointer handle;
78
79         *error = ERROR_SUCCESS;
80
81         handle = OpenEvent (rights, FALSE, mono_string_chars (name));
82         if (!handle)
83                 *error = GetLastError ();
84
85         return handle;
86 }