Make the DllRegisterServer, DllRegisterServerEx, DllUnregisterServer,
[wine/wine64.git] / scheduler / synchro.c
blob2537e1a722af7366e85e0391dbf542f78b143350
1 /*
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
21 #include "config.h"
23 #include "winbase.h"
24 #include "winternl.h"
25 #include "../kernel/kernel_private.h" /* FIXME: to be changed when moving file to dlls/kernel */
28 /***********************************************************************
29 * Sleep (KERNEL32.@)
31 VOID WINAPI Sleep( DWORD timeout )
33 SleepEx( timeout, FALSE );
36 /******************************************************************************
37 * SleepEx (KERNEL32.@)
39 DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
41 NTSTATUS status;
43 if (timeout == INFINITE) status = NtDelayExecution( alertable, NULL );
44 else
46 LARGE_INTEGER time;
48 time.QuadPart = timeout * (ULONGLONG)10000;
49 time.QuadPart = -time.QuadPart;
50 status = NtDelayExecution( alertable, &time );
52 if (status != STATUS_USER_APC) status = STATUS_SUCCESS;
53 return status;
57 /***********************************************************************
58 * WaitForSingleObject (KERNEL32.@)
60 DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout )
62 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
66 /***********************************************************************
67 * WaitForSingleObjectEx (KERNEL32.@)
69 DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout,
70 BOOL alertable )
72 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
76 /***********************************************************************
77 * WaitForMultipleObjects (KERNEL32.@)
79 DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles,
80 BOOL wait_all, DWORD timeout )
82 return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
86 /***********************************************************************
87 * WaitForMultipleObjectsEx (KERNEL32.@)
89 DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
90 BOOL wait_all, DWORD timeout,
91 BOOL alertable )
93 NTSTATUS status;
94 HANDLE hloc[MAXIMUM_WAIT_OBJECTS];
95 int i;
97 if (count >= MAXIMUM_WAIT_OBJECTS)
99 SetLastError(ERROR_INVALID_PARAMETER);
100 return WAIT_FAILED;
102 for (i = 0; i < count; i++)
104 if ((handles[i] == (HANDLE)STD_INPUT_HANDLE) ||
105 (handles[i] == (HANDLE)STD_OUTPUT_HANDLE) ||
106 (handles[i] == (HANDLE)STD_ERROR_HANDLE))
107 hloc[i] = GetStdHandle( (DWORD)handles[i] );
108 else
109 hloc[i] = handles[i];
111 /* yes, even screen buffer console handles are waitable, and are
112 * handled as a handle to the console itself !!
114 if (is_console_handle(hloc[i]))
116 if (!VerifyConsoleIoHandle(hloc[i]))
118 return FALSE;
120 hloc[i] = GetConsoleInputWaitHandle();
124 if (timeout == INFINITE)
126 status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, NULL );
128 else
130 LARGE_INTEGER time;
132 time.QuadPart = timeout * (ULONGLONG)10000;
133 time.QuadPart = -time.QuadPart;
134 status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, &time );
137 if (HIWORD(status)) /* is it an error code? */
139 SetLastError( RtlNtStatusToDosError(status) );
140 status = WAIT_FAILED;
142 return status;
146 /***********************************************************************
147 * WaitForSingleObject (KERNEL.460)
149 DWORD WINAPI WaitForSingleObject16( HANDLE handle, DWORD timeout )
151 DWORD retval, mutex_count;
153 ReleaseThunkLock( &mutex_count );
154 retval = WaitForSingleObject( handle, timeout );
155 RestoreThunkLock( mutex_count );
156 return retval;
159 /***********************************************************************
160 * WaitForMultipleObjects (KERNEL.461)
162 DWORD WINAPI WaitForMultipleObjects16( DWORD count, const HANDLE *handles,
163 BOOL wait_all, DWORD timeout )
165 DWORD retval, mutex_count;
167 ReleaseThunkLock( &mutex_count );
168 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
169 RestoreThunkLock( mutex_count );
170 return retval;
173 /***********************************************************************
174 * WaitForMultipleObjectsEx (KERNEL.495)
176 DWORD WINAPI WaitForMultipleObjectsEx16( DWORD count, const HANDLE *handles,
177 BOOL wait_all, DWORD timeout, BOOL alertable )
179 DWORD retval, mutex_count;
181 ReleaseThunkLock( &mutex_count );
182 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable );
183 RestoreThunkLock( mutex_count );
184 return retval;