Reduce TLS accesses. (#11487)
[mono-project.git] / mono / metadata / w32event-win32.c
blob73d8679a1dfe93c391349ebd4e2c51abb004bb15
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>
18 void
19 mono_w32event_init (void)
23 gpointer
24 mono_w32event_create (gboolean manual, gboolean initial)
26 return CreateEvent (NULL, manual, initial, NULL);
29 gboolean
30 mono_w32event_close (gpointer handle)
32 return CloseHandle (handle);
35 void
36 mono_w32event_set (gpointer handle)
38 SetEvent (handle);
41 void
42 mono_w32event_reset (gpointer handle)
44 ResetEvent (handle);
47 gpointer
48 ves_icall_System_Threading_Events_CreateEvent_internal (MonoBoolean manual, MonoBoolean initial, MonoStringHandle name, gint32 *err, MonoError *error)
50 gpointer event;
52 error_init (error);
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_internal (gchandle);
65 return event;
68 gboolean
69 ves_icall_System_Threading_Events_SetEvent_internal (gpointer handle)
71 return SetEvent (handle);
74 gboolean
75 ves_icall_System_Threading_Events_ResetEvent_internal (gpointer handle)
77 return ResetEvent (handle);
80 void
81 ves_icall_System_Threading_Events_CloseEvent_internal (gpointer handle)
83 CloseHandle (handle);
86 gpointer
87 ves_icall_System_Threading_Events_OpenEvent_internal (MonoStringHandle name, gint32 rights, gint32 *err, MonoError *error)
89 gpointer handle;
91 error_init (error);
93 *err = ERROR_SUCCESS;
95 uint32_t gchandle = 0;
96 gunichar2 *uniname = NULL;
98 if (!MONO_HANDLE_IS_NULL (name))
99 uniname = mono_string_handle_pin_chars (name, &gchandle);
101 MONO_ENTER_GC_SAFE;
102 handle = OpenEvent (rights, FALSE, uniname);
103 if (!handle)
104 *err = GetLastError ();
105 MONO_EXIT_GC_SAFE;
107 if (gchandle)
108 mono_gchandle_free_internal (gchandle);
110 return handle;