2 * os-event-win32.c: MonoOSEvent on Win32
5 * Ludovic Henry (luhenry@microsoft.com)
7 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
18 mono_os_event_init (MonoOSEvent *event, gboolean initial)
22 event->handle = CreateEvent (NULL, TRUE, initial, NULL);
23 if (G_UNLIKELY (!event->handle))
24 g_error ("%s: CreateEvent failed with error %d", __func__, GetLastError ());
28 mono_os_event_destroy (MonoOSEvent *event)
33 g_assert (event->handle);
35 res = CloseHandle (event->handle);
36 if (G_UNLIKELY (res == 0))
37 g_error ("%s: CloseHandle failed with error %d", __func__, GetLastError ());
41 mono_os_event_set (MonoOSEvent *event)
46 g_assert (event->handle);
48 res = SetEvent (event->handle);
49 if (G_UNLIKELY (res == 0))
50 g_error ("%s: SetEvent failed with error %d", __func__, GetLastError ());
54 mono_os_event_reset (MonoOSEvent *event)
59 g_assert (event->handle);
61 res = ResetEvent (event->handle);
62 if (G_UNLIKELY (res == 0))
63 g_error ("%s: ResetEvent failed with error %d", __func__, GetLastError ());
67 mono_os_event_wait_one (MonoOSEvent *event, guint32 timeout)
72 g_assert (event->handle);
74 res = WaitForSingleObjectEx (event->handle, timeout, TRUE);
75 if (res == WAIT_OBJECT_0)
76 return MONO_OS_EVENT_WAIT_RET_SUCCESS_0;
77 else if (res == WAIT_IO_COMPLETION)
78 return MONO_OS_EVENT_WAIT_RET_ALERTED;
79 else if (res == WAIT_TIMEOUT)
80 return MONO_OS_EVENT_WAIT_RET_TIMEOUT;
81 else if (res == WAIT_FAILED)
82 g_error ("%s: WaitForSingleObjectEx failed with error %d", __func__, GetLastError ());
84 g_error ("%s: unknown res value %d", __func__, res);
88 mono_os_event_wait_multiple (MonoOSEvent **events, gsize nevents, gboolean waitall, guint32 timeout)
91 gpointer handles [MONO_OS_EVENT_WAIT_MAXIMUM_OBJECTS];
95 g_assert (nevents > 0);
96 g_assert (nevents <= MONO_OS_EVENT_WAIT_MAXIMUM_OBJECTS);
99 return mono_os_event_wait_one (events [0], timeout);
101 for (i = 0; i < nevents; ++i) {
102 g_assert (events [i]);
103 g_assert (events [i]->handle);
104 handles [i] = events [i]->handle;
107 res = WaitForMultipleObjectsEx (nevents, handles, waitall, timeout, TRUE);
108 if (res >= WAIT_OBJECT_0 && res < WAIT_OBJECT_0 + MONO_OS_EVENT_WAIT_MAXIMUM_OBJECTS)
109 return MONO_OS_EVENT_WAIT_RET_SUCCESS_0 + (res - WAIT_OBJECT_0);
110 else if (res == WAIT_IO_COMPLETION)
111 return MONO_OS_EVENT_WAIT_RET_ALERTED;
112 else if (res == WAIT_TIMEOUT)
113 return MONO_OS_EVENT_WAIT_RET_TIMEOUT;
114 else if (res == WAIT_FAILED)
115 g_error ("%s: WaitForSingleObjectEx failed with error %d", __func__, GetLastError ());
117 g_error ("%s: unknown res value %d", __func__, res);