Test for static was reversed.
[wine.git] / scheduler / synchro.c
blobec73de732711e95ef4de901e97a0d52cb03f7b59
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 "server.h"
17 #include "debug.h"
20 /***********************************************************************
21 * Sleep (KERNEL32.679)
23 VOID WINAPI Sleep( DWORD timeout )
25 WaitForMultipleObjectsEx( 0, NULL, FALSE, timeout, FALSE );
28 /******************************************************************************
29 * SleepEx (KERNEL32.680)
31 DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
33 DWORD ret = WaitForMultipleObjectsEx( 0, NULL, FALSE, timeout, alertable );
34 if (ret != WAIT_IO_COMPLETION) ret = 0;
35 return ret;
39 /***********************************************************************
40 * WaitForSingleObject (KERNEL32.723)
42 DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout )
44 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
48 /***********************************************************************
49 * WaitForSingleObjectEx (KERNEL32.724)
51 DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout,
52 BOOL alertable )
54 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
58 /***********************************************************************
59 * WaitForMultipleObjects (KERNEL32.721)
61 DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles,
62 BOOL wait_all, DWORD timeout )
64 return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
68 /***********************************************************************
69 * WaitForMultipleObjectsEx (KERNEL32.722)
71 DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
72 BOOL wait_all, DWORD timeout,
73 BOOL alertable )
75 struct select_request req;
76 struct select_reply reply;
77 int server_handle[MAXIMUM_WAIT_OBJECTS];
78 void *apc[32];
79 int i, len;
81 if (count > MAXIMUM_WAIT_OBJECTS)
83 SetLastError( ERROR_INVALID_PARAMETER );
84 return WAIT_FAILED;
87 for (i = 0; i < count; i++) server_handle[i] = handles[i];
89 req.count = count;
90 req.flags = 0;
91 req.timeout = timeout;
93 if (wait_all) req.flags |= SELECT_ALL;
94 if (alertable) req.flags |= SELECT_ALERTABLE;
95 if (timeout != INFINITE) req.flags |= SELECT_TIMEOUT;
97 CLIENT_SendRequest( REQ_SELECT, -1, 2,
98 &req, sizeof(req),
99 server_handle, count * sizeof(int) );
100 CLIENT_WaitReply( &len, NULL, 2, &reply, sizeof(reply),
101 apc, sizeof(apc) );
102 if ((reply.signaled == STATUS_USER_APC) && (len > sizeof(reply)))
104 int i;
105 len -= sizeof(reply);
106 for (i = 0; i < len / sizeof(void*); i += 2)
108 PAPCFUNC func = (PAPCFUNC)apc[i];
109 if ( func ) func( (ULONG_PTR)apc[i+1] );
112 return reply.signaled;
116 /***********************************************************************
117 * WIN16_WaitForSingleObject (KERNEL.460)
119 DWORD WINAPI WIN16_WaitForSingleObject( HANDLE handle, DWORD timeout )
121 DWORD retval;
123 SYSLEVEL_ReleaseWin16Lock();
124 retval = WaitForSingleObject( handle, timeout );
125 SYSLEVEL_RestoreWin16Lock();
127 return retval;
130 /***********************************************************************
131 * WIN16_WaitForMultipleObjects (KERNEL.461)
133 DWORD WINAPI WIN16_WaitForMultipleObjects( DWORD count, const HANDLE *handles,
134 BOOL wait_all, DWORD timeout )
136 DWORD retval;
138 SYSLEVEL_ReleaseWin16Lock();
139 retval = WaitForMultipleObjects( count, handles, wait_all, timeout );
140 SYSLEVEL_RestoreWin16Lock();
142 return retval;
145 /***********************************************************************
146 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
148 DWORD WINAPI WIN16_WaitForMultipleObjectsEx( DWORD count,
149 const HANDLE *handles,
150 BOOL wait_all, DWORD timeout,
151 BOOL alertable )
153 DWORD retval;
155 SYSLEVEL_ReleaseWin16Lock();
156 retval = WaitForMultipleObjectsEx( count, handles,
157 wait_all, timeout, alertable );
158 SYSLEVEL_RestoreWin16Lock();
160 return retval;