Removed some unnecessary #includes and dll dependencies.
[wine/multimedia.git] / scheduler / synchro.c
blob26820e4f8a2bc5716ccfe56e345dbc1907bb873a
1 /*
2 * Win32 process and thread synchronisation
4 * Copyright 1997 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <signal.h>
9 #include <sys/time.h>
10 #include <unistd.h>
11 #include "heap.h"
12 #include "thread.h"
13 #include "winerror.h"
14 #include "syslevel.h"
15 #include "server.h"
17 /***********************************************************************
18 * call_apcs
20 * Call outstanding APCs.
22 static void call_apcs(void)
24 #define MAX_APCS 16
25 int i;
26 void *buffer[MAX_APCS * 2];
27 struct get_apcs_request *req = get_req_buffer();
29 if (server_call( REQ_GET_APCS ) || !req->count) return;
30 assert( req->count <= MAX_APCS );
31 memcpy( buffer, req->apcs, req->count * 2 * sizeof(req->apcs[0]) );
32 for (i = 0; i < req->count * 2; i += 2)
34 PAPCFUNC func = (PAPCFUNC)req->apcs[i];
35 if (func) func( (ULONG_PTR)req->apcs[i+1] );
39 /***********************************************************************
40 * Sleep (KERNEL32.679)
42 VOID WINAPI Sleep( DWORD timeout )
44 WaitForMultipleObjectsEx( 0, NULL, FALSE, timeout, FALSE );
47 /******************************************************************************
48 * SleepEx (KERNEL32.680)
50 DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
52 DWORD ret = WaitForMultipleObjectsEx( 0, NULL, FALSE, timeout, alertable );
53 if (ret != WAIT_IO_COMPLETION) ret = 0;
54 return ret;
58 /***********************************************************************
59 * WaitForSingleObject (KERNEL32.723)
61 DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout )
63 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
67 /***********************************************************************
68 * WaitForSingleObjectEx (KERNEL32.724)
70 DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout,
71 BOOL alertable )
73 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
77 /***********************************************************************
78 * WaitForMultipleObjects (KERNEL32.721)
80 DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles,
81 BOOL wait_all, DWORD timeout )
83 return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
87 /***********************************************************************
88 * WaitForMultipleObjectsEx (KERNEL32.722)
90 DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
91 BOOL wait_all, DWORD timeout,
92 BOOL alertable )
94 struct select_request *req = get_req_buffer();
95 int i, ret;
97 if (count > MAXIMUM_WAIT_OBJECTS)
99 SetLastError( ERROR_INVALID_PARAMETER );
100 return WAIT_FAILED;
103 req->count = count;
104 req->flags = 0;
105 req->timeout = timeout;
106 for (i = 0; i < count; i++) req->handles[i] = handles[i];
108 if (wait_all) req->flags |= SELECT_ALL;
109 if (alertable) req->flags |= SELECT_ALERTABLE;
110 if (timeout != INFINITE) req->flags |= SELECT_TIMEOUT;
112 server_call( REQ_SELECT );
113 if ((ret = req->signaled) == STATUS_USER_APC) call_apcs();
114 return ret;
118 /***********************************************************************
119 * WIN16_WaitForSingleObject (KERNEL.460)
121 DWORD WINAPI WIN16_WaitForSingleObject( HANDLE handle, DWORD timeout )
123 DWORD retval;
125 SYSLEVEL_ReleaseWin16Lock();
126 retval = WaitForSingleObject( handle, timeout );
127 SYSLEVEL_RestoreWin16Lock();
129 return retval;
132 /***********************************************************************
133 * WIN16_WaitForMultipleObjects (KERNEL.461)
135 DWORD WINAPI WIN16_WaitForMultipleObjects( DWORD count, const HANDLE *handles,
136 BOOL wait_all, DWORD timeout )
138 DWORD retval;
140 SYSLEVEL_ReleaseWin16Lock();
141 retval = WaitForMultipleObjects( count, handles, wait_all, timeout );
142 SYSLEVEL_RestoreWin16Lock();
144 return retval;
147 /***********************************************************************
148 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
150 DWORD WINAPI WIN16_WaitForMultipleObjectsEx( DWORD count,
151 const HANDLE *handles,
152 BOOL wait_all, DWORD timeout,
153 BOOL alertable )
155 DWORD retval;
157 SYSLEVEL_ReleaseWin16Lock();
158 retval = WaitForMultipleObjectsEx( count, handles,
159 wait_all, timeout, alertable );
160 SYSLEVEL_RestoreWin16Lock();
162 return retval;