2 * Win32 process and thread synchronisation
4 * Copyright 1997 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "../kernel/kernel_private.h" /* FIXME: to be changed when moving file to dlls/kernel */
28 /***********************************************************************
31 VOID WINAPI
Sleep( DWORD timeout
)
33 WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, FALSE
);
36 /******************************************************************************
37 * SleepEx (KERNEL32.@)
39 DWORD WINAPI
SleepEx( DWORD timeout
, BOOL alertable
)
41 DWORD ret
= WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, alertable
);
42 if (ret
!= WAIT_IO_COMPLETION
) ret
= 0;
47 /***********************************************************************
48 * WaitForSingleObject (KERNEL32.@)
50 DWORD WINAPI
WaitForSingleObject( HANDLE handle
, DWORD timeout
)
52 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, FALSE
);
56 /***********************************************************************
57 * WaitForSingleObjectEx (KERNEL32.@)
59 DWORD WINAPI
WaitForSingleObjectEx( HANDLE handle
, DWORD timeout
,
62 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, alertable
);
66 /***********************************************************************
67 * WaitForMultipleObjects (KERNEL32.@)
69 DWORD WINAPI
WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
70 BOOL wait_all
, DWORD timeout
)
72 return WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
76 /***********************************************************************
77 * WaitForMultipleObjectsEx (KERNEL32.@)
79 DWORD WINAPI
WaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
,
80 BOOL wait_all
, DWORD timeout
,
84 HANDLE hloc
[MAXIMUM_WAIT_OBJECTS
];
87 if (count
>= MAXIMUM_WAIT_OBJECTS
)
89 SetLastError(ERROR_INVALID_PARAMETER
);
92 for (i
= 0; i
< count
; i
++)
94 if ((handles
[i
] == (HANDLE
)STD_INPUT_HANDLE
) ||
95 (handles
[i
] == (HANDLE
)STD_OUTPUT_HANDLE
) ||
96 (handles
[i
] == (HANDLE
)STD_ERROR_HANDLE
))
97 hloc
[i
] = GetStdHandle( (DWORD
)handles
[i
] );
101 /* yes, even screen buffer console handles are waitable, and are
102 * handled as a handle to the console itself !!
104 if (is_console_handle(hloc
[i
]))
106 if (!VerifyConsoleIoHandle(hloc
[i
]))
110 hloc
[i
] = GetConsoleInputWaitHandle();
114 if (timeout
== INFINITE
)
116 status
= NtWaitForMultipleObjects( count
, hloc
, wait_all
, alertable
, NULL
);
122 time
.QuadPart
= timeout
* (ULONGLONG
)10000;
123 time
.QuadPart
= -time
.QuadPart
;
124 status
= NtWaitForMultipleObjects( count
, hloc
, wait_all
, alertable
, &time
);
127 if (HIWORD(status
)) /* is it an error code? */
129 SetLastError( RtlNtStatusToDosError(status
) );
130 status
= WAIT_FAILED
;
136 /***********************************************************************
137 * WaitForSingleObject (KERNEL.460)
139 DWORD WINAPI
WaitForSingleObject16( HANDLE handle
, DWORD timeout
)
141 DWORD retval
, mutex_count
;
143 ReleaseThunkLock( &mutex_count
);
144 retval
= WaitForSingleObject( handle
, timeout
);
145 RestoreThunkLock( mutex_count
);
149 /***********************************************************************
150 * WaitForMultipleObjects (KERNEL.461)
152 DWORD WINAPI
WaitForMultipleObjects16( DWORD count
, const HANDLE
*handles
,
153 BOOL wait_all
, DWORD timeout
)
155 DWORD retval
, mutex_count
;
157 ReleaseThunkLock( &mutex_count
);
158 retval
= WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
159 RestoreThunkLock( mutex_count
);
163 /***********************************************************************
164 * WaitForMultipleObjectsEx (KERNEL.495)
166 DWORD WINAPI
WaitForMultipleObjectsEx16( DWORD count
, const HANDLE
*handles
,
167 BOOL wait_all
, DWORD timeout
, BOOL alertable
)
169 DWORD retval
, mutex_count
;
171 ReleaseThunkLock( &mutex_count
);
172 retval
= WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, alertable
);
173 RestoreThunkLock( mutex_count
);