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