2 * Win32 process and thread synchronisation
4 * Copyright 1997 Alexandre Julliard
19 /***********************************************************************
22 * Call outstanding APCs.
24 static void call_apcs(void)
28 void *buffer[MAX_APCS * 2];
29 struct get_apcs_request *req = get_req_buffer();
31 if (server_call( REQ_GET_APCS ) || !req->count) return;
32 assert( req->count <= MAX_APCS );
33 memcpy( buffer, req->apcs, req->count * 2 * sizeof(req->apcs[0]) );
34 for (i = 0; i < req->count * 2; i += 2)
36 PAPCFUNC func = (PAPCFUNC)req->apcs[i];
37 if (func) func( (ULONG_PTR)req->apcs[i+1] );
41 /***********************************************************************
42 * Sleep (KERNEL32.679)
44 VOID WINAPI Sleep( DWORD timeout )
46 WaitForMultipleObjectsEx( 0, NULL, FALSE, timeout, FALSE );
49 /******************************************************************************
50 * SleepEx (KERNEL32.680)
52 DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
54 DWORD ret = WaitForMultipleObjectsEx( 0, NULL, FALSE, timeout, alertable );
55 if (ret != WAIT_IO_COMPLETION) ret = 0;
60 /***********************************************************************
61 * WaitForSingleObject (KERNEL32.723)
63 DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout )
65 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
69 /***********************************************************************
70 * WaitForSingleObjectEx (KERNEL32.724)
72 DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout,
75 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
79 /***********************************************************************
80 * WaitForMultipleObjects (KERNEL32.721)
82 DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles,
83 BOOL wait_all, DWORD timeout )
85 return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
89 /***********************************************************************
90 * WaitForMultipleObjectsEx (KERNEL32.722)
92 DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
93 BOOL wait_all, DWORD timeout,
96 struct select_request *req = get_req_buffer();
99 if (count > MAXIMUM_WAIT_OBJECTS)
101 SetLastError( ERROR_INVALID_PARAMETER );
107 req->timeout = timeout;
108 for (i = 0; i < count; i++) req->handles[i] = handles[i];
110 if (wait_all) req->flags |= SELECT_ALL;
111 if (alertable) req->flags |= SELECT_ALERTABLE;
112 if (timeout != INFINITE) req->flags |= SELECT_TIMEOUT;
114 server_call( REQ_SELECT );
115 if ((ret = req->signaled) == STATUS_USER_APC) call_apcs();
120 /***********************************************************************
121 * WIN16_WaitForSingleObject (KERNEL.460)
123 DWORD WINAPI WIN16_WaitForSingleObject( HANDLE handle, DWORD timeout )
127 SYSLEVEL_ReleaseWin16Lock();
128 retval = WaitForSingleObject( handle, timeout );
129 SYSLEVEL_RestoreWin16Lock();
134 /***********************************************************************
135 * WIN16_WaitForMultipleObjects (KERNEL.461)
137 DWORD WINAPI WIN16_WaitForMultipleObjects( DWORD count, const HANDLE *handles,
138 BOOL wait_all, DWORD timeout )
142 SYSLEVEL_ReleaseWin16Lock();
143 retval = WaitForMultipleObjects( count, handles, wait_all, timeout );
144 SYSLEVEL_RestoreWin16Lock();
149 /***********************************************************************
150 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
152 DWORD WINAPI WIN16_WaitForMultipleObjectsEx( DWORD count,
153 const HANDLE *handles,
154 BOOL wait_all, DWORD timeout,
159 SYSLEVEL_ReleaseWin16Lock();
160 retval = WaitForMultipleObjectsEx( count, handles,
161 wait_all, timeout, alertable );
162 SYSLEVEL_RestoreWin16Lock();