[io-layer] Remove unused WaitForMultipleObjects
[mono.git] / mono / io-layer / wait.c
1 /*
2  * wait.c:  wait for handles to become signalled
3  *
4  * Author:
5  *      Dick Porter (dick@ximian.com)
6  *
7  * (C) 2002-2006 Novell, Inc.
8  */
9
10 #include <config.h>
11 #include <glib.h>
12 #include <string.h>
13 #include <errno.h>
14
15 #include <mono/io-layer/wapi.h>
16 #include <mono/io-layer/wapi-private.h>
17 #include <mono/utils/w32handle.h>
18
19 /**
20  * WaitForSingleObjectEx:
21  * @handle: an object to wait for
22  * @timeout: the maximum time in milliseconds to wait for
23  * @alertable: if TRUE, the wait can be interrupted by an APC call
24  *
25  * This function returns when either @handle is signalled, or @timeout
26  * ms elapses.  If @timeout is zero, the object's state is tested and
27  * the function returns immediately.  If @timeout is %INFINITE, the
28  * function waits forever.
29  *
30  * Return value: %WAIT_ABANDONED - @handle is a mutex that was not
31  * released by the owning thread when it exited.  Ownership of the
32  * mutex object is granted to the calling thread and the mutex is set
33  * to nonsignalled.  %WAIT_OBJECT_0 - The state of @handle is
34  * signalled.  %WAIT_TIMEOUT - The @timeout interval elapsed and
35  * @handle's state is still not signalled.  %WAIT_FAILED - an error
36  * occurred. %WAIT_IO_COMPLETION - the wait was ended by an APC.
37  */
38 guint32 WaitForSingleObjectEx(gpointer handle, guint32 timeout, gboolean alertable)
39 {
40         MonoW32HandleWaitRet ret;
41
42         ret = mono_w32handle_wait_one (handle, timeout, alertable);
43         if (ret == MONO_W32HANDLE_WAIT_RET_SUCCESS_0)
44                 return WAIT_OBJECT_0;
45         else if (ret == MONO_W32HANDLE_WAIT_RET_ALERTED)
46                 return WAIT_IO_COMPLETION;
47         else if (ret == MONO_W32HANDLE_WAIT_RET_TIMEOUT)
48                 return WAIT_TIMEOUT;
49         else if (ret == MONO_W32HANDLE_WAIT_RET_FAILED)
50                 return WAIT_FAILED;
51         else
52                 g_error ("%s: unknown ret value %d", __func__, ret);
53 }
54
55
56 /**
57  * SignalObjectAndWait:
58  * @signal_handle: An object to signal
59  * @wait: An object to wait for
60  * @timeout: The maximum time in milliseconds to wait for
61  * @alertable: Specifies whether the function returnes when the system
62  * queues an I/O completion routine or an APC for the calling thread.
63  *
64  * Atomically signals @signal and waits for @wait to become signalled,
65  * or @timeout ms elapses.  If @timeout is zero, the object's state is
66  * tested and the function returns immediately.  If @timeout is
67  * %INFINITE, the function waits forever.
68  *
69  * @signal can be a semaphore, mutex or event object.
70  *
71  * If @alertable is %TRUE and the system queues an I/O completion
72  * routine or an APC for the calling thread, the function returns and
73  * the thread calls the completion routine or APC function.  If
74  * %FALSE, the function does not return, and the thread does not call
75  * the completion routine or APC function.  A completion routine is
76  * queued when the ReadFileEx() or WriteFileEx() function in which it
77  * was specified has completed.  The calling thread is the thread that
78  * initiated the read or write operation.  An APC is queued when
79  * QueueUserAPC() is called.  Currently completion routines and APC
80  * functions are not supported.
81  *
82  * Return value: %WAIT_ABANDONED - @wait is a mutex that was not
83  * released by the owning thread when it exited.  Ownershop of the
84  * mutex object is granted to the calling thread and the mutex is set
85  * to nonsignalled.  %WAIT_IO_COMPLETION - the wait was ended by one
86  * or more user-mode asynchronous procedure calls queued to the
87  * thread.  %WAIT_OBJECT_0 - The state of @wait is signalled.
88  * %WAIT_TIMEOUT - The @timeout interval elapsed and @wait's state is
89  * still not signalled.  %WAIT_FAILED - an error occurred.
90  */
91 guint32 SignalObjectAndWait(gpointer signal_handle, gpointer wait,
92                             guint32 timeout, gboolean alertable)
93 {
94         MonoW32HandleWaitRet ret;
95
96         ret = mono_w32handle_signal_and_wait (signal_handle, wait, timeout, alertable);
97         if (ret == MONO_W32HANDLE_WAIT_RET_SUCCESS_0)
98                 return WAIT_OBJECT_0;
99         else if (ret == MONO_W32HANDLE_WAIT_RET_ALERTED)
100                 return WAIT_IO_COMPLETION;
101         else if (ret == MONO_W32HANDLE_WAIT_RET_TIMEOUT)
102                 return WAIT_TIMEOUT;
103         else if (ret == MONO_W32HANDLE_WAIT_RET_FAILED)
104                 return WAIT_FAILED;
105         else
106                 g_error ("%s: unknown ret value %d", __func__, ret);
107 }
108
109 /**
110  * WaitForMultipleObjectsEx:
111  * @numobjects: The number of objects in @handles. The maximum allowed
112  * is %MAXIMUM_WAIT_OBJECTS.
113  * @handles: An array of object handles.  Duplicates are not allowed.
114  * @waitall: If %TRUE, this function waits until all of the handles
115  * are signalled.  If %FALSE, this function returns when any object is
116  * signalled.
117  * @timeout: The maximum time in milliseconds to wait for.
118  * @alertable: if TRUE, the wait can be interrupted by an APC call
119  * 
120  * This function returns when either one or more of @handles is
121  * signalled, or @timeout ms elapses.  If @timeout is zero, the state
122  * of each item of @handles is tested and the function returns
123  * immediately.  If @timeout is %INFINITE, the function waits forever.
124  *
125  * Return value: %WAIT_OBJECT_0 to %WAIT_OBJECT_0 + @numobjects - 1 -
126  * if @waitall is %TRUE, indicates that all objects are signalled.  If
127  * @waitall is %FALSE, the return value minus %WAIT_OBJECT_0 indicates
128  * the first index into @handles of the objects that are signalled.
129  * %WAIT_ABANDONED_0 to %WAIT_ABANDONED_0 + @numobjects - 1 - if
130  * @waitall is %TRUE, indicates that all objects are signalled, and at
131  * least one object is an abandoned mutex object (See
132  * WaitForSingleObject() for a description of abandoned mutexes.)  If
133  * @waitall is %FALSE, the return value minus %WAIT_ABANDONED_0
134  * indicates the first index into @handles of an abandoned mutex.
135  * %WAIT_TIMEOUT - The @timeout interval elapsed and no objects in
136  * @handles are signalled.  %WAIT_FAILED - an error occurred.
137  * %WAIT_IO_COMPLETION - the wait was ended by an APC.
138  */
139 guint32 WaitForMultipleObjectsEx(guint32 numobjects, gpointer *handles,
140                                  gboolean waitall, guint32 timeout,
141                                  gboolean alertable)
142 {
143         MonoW32HandleWaitRet ret;
144
145         ret = mono_w32handle_wait_multiple (handles, numobjects, waitall, timeout, alertable);
146         if (ret >= MONO_W32HANDLE_WAIT_RET_SUCCESS_0)
147                 return WAIT_OBJECT_0 + (ret - MONO_W32HANDLE_WAIT_RET_SUCCESS_0);
148         else if (ret == MONO_W32HANDLE_WAIT_RET_ALERTED)
149                 return WAIT_IO_COMPLETION;
150         else if (ret == MONO_W32HANDLE_WAIT_RET_TIMEOUT)
151                 return WAIT_TIMEOUT;
152         else if (ret == MONO_W32HANDLE_WAIT_RET_FAILED)
153                 return WAIT_FAILED;
154         else
155                 g_error ("%s: unknown ret value %d", __func__, ret);
156 }
157
158 /**
159  * WaitForInputIdle:
160  * @handle: a handle to the process to wait for
161  * @timeout: the maximum time in milliseconds to wait for
162  *
163  * This function returns when either @handle process is waiting
164  * for input, or @timeout ms elapses.  If @timeout is zero, the
165  * process state is tested and the function returns immediately.
166  * If @timeout is %INFINITE, the function waits forever.
167  *
168  * Return value: 0 - @handle process is waiting for input.
169  * %WAIT_TIMEOUT - The @timeout interval elapsed and
170  * @handle process is not waiting for input.  %WAIT_FAILED - an error
171  * occurred. 
172  */
173 guint32 WaitForInputIdle(gpointer handle, guint32 timeout)
174 {
175         /*TODO: Not implemented*/
176         return WAIT_TIMEOUT;
177 }
178