Added context functions for FreeBSD.
[wine/multimedia.git] / scheduler / synchro.c
blobbd8724b8fef75f6fc7c2ec8146a4f3aaa68aa7a7
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 "process.h"
13 #include "thread.h"
14 #include "winerror.h"
15 #include "syslevel.h"
16 #include "message.h"
17 #include "x11drv.h"
18 #include "server.h"
20 /***********************************************************************
21 * call_apcs
23 * Call outstanding APCs.
25 static void call_apcs(void)
27 #define MAX_APCS 16
28 int i;
29 void *buffer[MAX_APCS * 2];
30 struct get_apcs_request *req = get_req_buffer();
32 if (server_call( REQ_GET_APCS ) || !req->count) return;
33 assert( req->count <= MAX_APCS );
34 memcpy( buffer, req->apcs, req->count * 2 * sizeof(req->apcs[0]) );
35 for (i = 0; i < req->count * 2; i += 2)
37 PAPCFUNC func = (PAPCFUNC)req->apcs[i];
38 if (func) func( (ULONG_PTR)req->apcs[i+1] );
42 /***********************************************************************
43 * Sleep (KERNEL32.679)
45 VOID WINAPI Sleep( DWORD timeout )
47 WaitForMultipleObjectsEx( 0, NULL, FALSE, timeout, FALSE );
50 /******************************************************************************
51 * SleepEx (KERNEL32.680)
53 DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
55 DWORD ret = WaitForMultipleObjectsEx( 0, NULL, FALSE, timeout, alertable );
56 if (ret != WAIT_IO_COMPLETION) ret = 0;
57 return ret;
61 /***********************************************************************
62 * WaitForSingleObject (KERNEL32.723)
64 DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout )
66 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
70 /***********************************************************************
71 * WaitForSingleObjectEx (KERNEL32.724)
73 DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout,
74 BOOL alertable )
76 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
80 /***********************************************************************
81 * WaitForMultipleObjects (KERNEL32.721)
83 DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles,
84 BOOL wait_all, DWORD timeout )
86 return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
90 /***********************************************************************
91 * WaitForMultipleObjectsEx (KERNEL32.722)
93 DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
94 BOOL wait_all, DWORD timeout,
95 BOOL alertable )
97 struct select_request *req = get_req_buffer();
98 int i, ret;
100 if (count > MAXIMUM_WAIT_OBJECTS)
102 SetLastError( ERROR_INVALID_PARAMETER );
103 return WAIT_FAILED;
106 req->count = count;
107 req->flags = 0;
108 req->timeout = timeout;
109 for (i = 0; i < count; i++) req->handles[i] = handles[i];
111 if (wait_all) req->flags |= SELECT_ALL;
112 if (alertable) req->flags |= SELECT_ALERTABLE;
113 if (timeout != INFINITE) req->flags |= SELECT_TIMEOUT;
115 server_call( REQ_SELECT );
116 if ((ret = req->signaled) == STATUS_USER_APC) call_apcs();
117 return ret;
121 /***********************************************************************
122 * WIN16_WaitForSingleObject (KERNEL.460)
124 DWORD WINAPI WIN16_WaitForSingleObject( HANDLE handle, DWORD timeout )
126 DWORD retval;
128 SYSLEVEL_ReleaseWin16Lock();
129 retval = WaitForSingleObject( handle, timeout );
130 SYSLEVEL_RestoreWin16Lock();
132 return retval;
135 /***********************************************************************
136 * WIN16_WaitForMultipleObjects (KERNEL.461)
138 DWORD WINAPI WIN16_WaitForMultipleObjects( DWORD count, const HANDLE *handles,
139 BOOL wait_all, DWORD timeout )
141 DWORD retval;
143 SYSLEVEL_ReleaseWin16Lock();
144 retval = WaitForMultipleObjects( count, handles, wait_all, timeout );
145 SYSLEVEL_RestoreWin16Lock();
147 return retval;
150 /***********************************************************************
151 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
153 DWORD WINAPI WIN16_WaitForMultipleObjectsEx( DWORD count,
154 const HANDLE *handles,
155 BOOL wait_all, DWORD timeout,
156 BOOL alertable )
158 DWORD retval;
160 SYSLEVEL_ReleaseWin16Lock();
161 retval = WaitForMultipleObjectsEx( count, handles,
162 wait_all, timeout, alertable );
163 SYSLEVEL_RestoreWin16Lock();
165 return retval;