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
27 /***********************************************************************
30 VOID WINAPI
Sleep( DWORD timeout
)
32 WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, FALSE
);
35 /******************************************************************************
36 * SleepEx (KERNEL32.@)
38 DWORD WINAPI
SleepEx( DWORD timeout
, BOOL alertable
)
40 DWORD ret
= WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, alertable
);
41 if (ret
!= WAIT_IO_COMPLETION
) ret
= 0;
46 /***********************************************************************
47 * WaitForSingleObject (KERNEL32.@)
49 DWORD WINAPI
WaitForSingleObject( HANDLE handle
, DWORD timeout
)
51 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, FALSE
);
55 /***********************************************************************
56 * WaitForSingleObjectEx (KERNEL32.@)
58 DWORD WINAPI
WaitForSingleObjectEx( HANDLE handle
, DWORD timeout
,
61 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, alertable
);
65 /***********************************************************************
66 * WaitForMultipleObjects (KERNEL32.@)
68 DWORD WINAPI
WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
69 BOOL wait_all
, DWORD timeout
)
71 return WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
75 /***********************************************************************
76 * WaitForMultipleObjectsEx (KERNEL32.@)
78 DWORD WINAPI
WaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
,
79 BOOL wait_all
, DWORD timeout
,
84 if (timeout
== INFINITE
)
86 status
= NtWaitForMultipleObjects( count
, handles
, wait_all
, alertable
, NULL
);
92 time
.QuadPart
= timeout
* (ULONGLONG
)10000;
93 time
.QuadPart
= -time
.QuadPart
;
94 status
= NtWaitForMultipleObjects( count
, handles
, wait_all
, alertable
, &time
);
97 if (HIWORD(status
)) /* is it an error code? */
99 SetLastError( RtlNtStatusToDosError(status
) );
100 status
= WAIT_FAILED
;
106 /***********************************************************************
107 * WaitForSingleObject (KERNEL.460)
109 DWORD WINAPI
WaitForSingleObject16( HANDLE handle
, DWORD timeout
)
111 DWORD retval
, mutex_count
;
113 ReleaseThunkLock( &mutex_count
);
114 retval
= WaitForSingleObject( handle
, timeout
);
115 RestoreThunkLock( mutex_count
);
119 /***********************************************************************
120 * WaitForMultipleObjects (KERNEL.461)
122 DWORD WINAPI
WaitForMultipleObjects16( DWORD count
, const HANDLE
*handles
,
123 BOOL wait_all
, DWORD timeout
)
125 DWORD retval
, mutex_count
;
127 ReleaseThunkLock( &mutex_count
);
128 retval
= WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
129 RestoreThunkLock( mutex_count
);
133 /***********************************************************************
134 * WaitForMultipleObjectsEx (KERNEL.495)
136 DWORD WINAPI
WaitForMultipleObjectsEx16( DWORD count
, const HANDLE
*handles
,
137 BOOL wait_all
, DWORD timeout
, BOOL alertable
)
139 DWORD retval
, mutex_count
;
141 ReleaseThunkLock( &mutex_count
);
142 retval
= WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, alertable
);
143 RestoreThunkLock( mutex_count
);