6 * Ludovic Henry (luhenry@microsoft.com)
8 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
19 mono_os_event_init (MonoOSEvent *event, gboolean initial)
23 event->handle = CreateEvent (NULL, TRUE, initial, NULL);
24 if (G_UNLIKELY (!event->handle))
25 g_error ("%s: CreateEvent failed with error %d", __func__, GetLastError ());
29 mono_os_event_destroy (MonoOSEvent *event)
34 g_assert (event->handle);
36 res = CloseHandle (event->handle);
37 if (G_UNLIKELY (res == 0))
38 g_error ("%s: CloseHandle failed with error %d", __func__, GetLastError ());
42 mono_os_event_set (MonoOSEvent *event)
47 g_assert (event->handle);
49 res = SetEvent (event->handle);
50 if (G_UNLIKELY (res == 0))
51 g_error ("%s: SetEvent failed with error %d", __func__, GetLastError ());
55 mono_os_event_reset (MonoOSEvent *event)
60 g_assert (event->handle);
62 res = ResetEvent (event->handle);
63 if (G_UNLIKELY (res == 0))
64 g_error ("%s: ResetEvent failed with error %d", __func__, GetLastError ());
68 mono_os_event_wait_one (MonoOSEvent *event, guint32 timeout, gboolean alertable)
73 g_assert (event->handle);
75 res = WaitForSingleObjectEx (event->handle, timeout, alertable);
76 if (res == WAIT_OBJECT_0)
77 return MONO_OS_EVENT_WAIT_RET_SUCCESS_0;
78 else if (res == WAIT_IO_COMPLETION)
79 return MONO_OS_EVENT_WAIT_RET_ALERTED;
80 else if (res == WAIT_TIMEOUT)
81 return MONO_OS_EVENT_WAIT_RET_TIMEOUT;
82 else if (res == WAIT_FAILED)
83 g_error ("%s: WaitForSingleObjectEx failed with error %d", __func__, GetLastError ());
85 g_error ("%s: unknown res value %d", __func__, res);
89 mono_os_event_wait_multiple (MonoOSEvent **events, gsize nevents, gboolean waitall, guint32 timeout, gboolean alertable)
92 gpointer handles [MONO_OS_EVENT_WAIT_MAXIMUM_OBJECTS];
96 g_assert (nevents > 0);
97 g_assert (nevents <= MONO_OS_EVENT_WAIT_MAXIMUM_OBJECTS);
100 return mono_os_event_wait_one (events [0], timeout, alertable);
102 for (i = 0; i < nevents; ++i) {
103 g_assert (events [i]);
104 g_assert (events [i]->handle);
105 handles [i] = events [i]->handle;
108 res = WaitForMultipleObjectsEx (nevents, handles, waitall, timeout, alertable);
109 if (res >= WAIT_OBJECT_0 && res < WAIT_OBJECT_0 + MONO_OS_EVENT_WAIT_MAXIMUM_OBJECTS)
110 return MONO_OS_EVENT_WAIT_RET_SUCCESS_0 + (res - WAIT_OBJECT_0);
111 else if (res == WAIT_IO_COMPLETION)
112 return MONO_OS_EVENT_WAIT_RET_ALERTED;
113 else if (res == WAIT_TIMEOUT)
114 return MONO_OS_EVENT_WAIT_RET_TIMEOUT;
115 else if (res == WAIT_FAILED)
116 g_error ("%s: WaitForSingleObjectEx failed with error %d", __func__, GetLastError ());
118 g_error ("%s: unknown res value %d", __func__, res);