Merge pull request #5714 from alexischr/update_bockbuild
[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 #include <mono/metadata/handle.h>
16 #include <mono/utils/mono-error-internals.h>
17
18 void
19 mono_w32event_init (void)
20 {
21 }
22
23 gpointer
24 mono_w32event_create (gboolean manual, gboolean initial)
25 {
26         return CreateEvent (NULL, manual, initial, NULL);
27 }
28
29 gboolean
30 mono_w32event_close (gpointer handle)
31 {
32         return CloseHandle (handle);
33 }
34
35 void
36 mono_w32event_set (gpointer handle)
37 {
38         SetEvent (handle);
39 }
40
41 void
42 mono_w32event_reset (gpointer handle)
43 {
44         ResetEvent (handle);
45 }
46
47 gpointer
48 ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoStringHandle name, gint32 *err, MonoError *error)
49 {
50         gpointer event;
51
52         error_init (error);
53         
54         uint32_t gchandle = 0;
55         gunichar2 *uniname = NULL;
56         if (!MONO_HANDLE_IS_NULL (name))
57                 uniname = mono_string_handle_pin_chars (name, &gchandle);
58         MONO_ENTER_GC_SAFE;
59         event = CreateEvent (NULL, manual, initial, uniname);
60         *err = GetLastError ();
61         MONO_EXIT_GC_SAFE;
62         if (gchandle)
63                 mono_gchandle_free (gchandle);
64
65         return event;
66 }
67
68 gboolean
69 ves_icall_System_Threading_Events_SetEvent_internal (gpointer handle)
70 {
71         return SetEvent (handle);
72 }
73
74 gboolean
75 ves_icall_System_Threading_Events_ResetEvent_internal (gpointer handle)
76 {
77         return ResetEvent (handle);
78 }
79
80 void
81 ves_icall_System_Threading_Events_CloseEvent_internal (gpointer handle)
82 {
83         CloseHandle (handle);
84 }
85
86 gpointer
87 ves_icall_System_Threading_Events_OpenEvent_internal (MonoStringHandle name, gint32 rights, gint32 *err, MonoError *error)
88 {
89         gpointer handle;
90
91         error_init (error);
92
93         *err = ERROR_SUCCESS;
94
95         uint32_t gchandle = 0;
96         gunichar2 *uniname = NULL;
97
98         if (!MONO_HANDLE_IS_NULL (name))
99                 uniname = mono_string_handle_pin_chars (name, &gchandle);
100
101         MONO_ENTER_GC_SAFE;
102         handle = OpenEvent (rights, FALSE, uniname);
103         if (!handle)
104                 *err = GetLastError ();
105         MONO_EXIT_GC_SAFE;
106
107         if (gchandle)
108                 mono_gchandle_free (gchandle);
109
110         return handle;
111 }