2 * Win32 process and thread synchronisation
4 * Copyright 1997 Alexandre Julliard
17 /***********************************************************************
20 * Call outstanding APCs.
22 static void call_apcs(void)
26 void *buffer
[MAX_APCS
* 2];
28 struct get_apcs_request
*req
= get_req_buffer();
30 if (server_call( REQ_GET_APCS
) || !req
->count
) return;
31 assert( req
->count
<= MAX_APCS
);
33 /* make a copy of the request buffer... it may get trashed *
34 * when the apcs are called */
35 memcpy( buffer
, req
->apcs
, req
->count
* 2 * sizeof(req
->apcs
[0]) );
38 for (i
= 0; i
< count
* 2; i
+= 2)
40 PAPCFUNC func
= (PAPCFUNC
)buffer
[i
];
41 if (func
) func( (ULONG_PTR
)buffer
[i
+1] );
45 /***********************************************************************
46 * Sleep (KERNEL32.679)
48 VOID WINAPI
Sleep( DWORD timeout
)
50 WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, FALSE
);
53 /******************************************************************************
54 * SleepEx (KERNEL32.680)
56 DWORD WINAPI
SleepEx( DWORD timeout
, BOOL alertable
)
58 DWORD ret
= WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, alertable
);
59 if (ret
!= WAIT_IO_COMPLETION
) ret
= 0;
64 /***********************************************************************
65 * WaitForSingleObject (KERNEL32.723)
67 DWORD WINAPI
WaitForSingleObject( HANDLE handle
, DWORD timeout
)
69 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, FALSE
);
73 /***********************************************************************
74 * WaitForSingleObjectEx (KERNEL32.724)
76 DWORD WINAPI
WaitForSingleObjectEx( HANDLE handle
, DWORD timeout
,
79 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, alertable
);
83 /***********************************************************************
84 * WaitForMultipleObjects (KERNEL32.721)
86 DWORD WINAPI
WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
87 BOOL wait_all
, DWORD timeout
)
89 return WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
93 /***********************************************************************
94 * WaitForMultipleObjectsEx (KERNEL32.722)
96 DWORD WINAPI
WaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
,
97 BOOL wait_all
, DWORD timeout
,
100 struct select_request
*req
= get_req_buffer();
103 if (count
> MAXIMUM_WAIT_OBJECTS
)
105 SetLastError( ERROR_INVALID_PARAMETER
);
111 req
->timeout
= timeout
;
112 for (i
= 0; i
< count
; i
++) req
->handles
[i
] = handles
[i
];
114 if (wait_all
) req
->flags
|= SELECT_ALL
;
115 if (alertable
) req
->flags
|= SELECT_ALERTABLE
;
116 if (timeout
!= INFINITE
) req
->flags
|= SELECT_TIMEOUT
;
118 server_call( REQ_SELECT
);
119 if ((ret
= req
->signaled
) == STATUS_USER_APC
) call_apcs();
124 /***********************************************************************
125 * WIN16_WaitForSingleObject (KERNEL.460)
127 DWORD WINAPI
WIN16_WaitForSingleObject( HANDLE handle
, DWORD timeout
)
131 SYSLEVEL_ReleaseWin16Lock();
132 retval
= WaitForSingleObject( handle
, timeout
);
133 SYSLEVEL_RestoreWin16Lock();
138 /***********************************************************************
139 * WIN16_WaitForMultipleObjects (KERNEL.461)
141 DWORD WINAPI
WIN16_WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
142 BOOL wait_all
, DWORD timeout
)
146 SYSLEVEL_ReleaseWin16Lock();
147 retval
= WaitForMultipleObjects( count
, handles
, wait_all
, timeout
);
148 SYSLEVEL_RestoreWin16Lock();
153 /***********************************************************************
154 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
156 DWORD WINAPI
WIN16_WaitForMultipleObjectsEx( DWORD count
,
157 const HANDLE
*handles
,
158 BOOL wait_all
, DWORD timeout
,
163 SYSLEVEL_ReleaseWin16Lock();
164 retval
= WaitForMultipleObjectsEx( count
, handles
,
165 wait_all
, timeout
, alertable
);
166 SYSLEVEL_RestoreWin16Lock();