2 * Win32 process and thread synchronisation
4 * Copyright 1997 Alexandre Julliard
20 /***********************************************************************
23 * Call outstanding APCs.
25 static void call_apcs(void)
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;
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
,
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
,
97 struct select_request
*req
= get_req_buffer();
100 if (count
> MAXIMUM_WAIT_OBJECTS
)
102 SetLastError( ERROR_INVALID_PARAMETER
);
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();
121 /***********************************************************************
122 * WIN16_WaitForSingleObject (KERNEL.460)
124 DWORD WINAPI
WIN16_WaitForSingleObject( HANDLE handle
, DWORD timeout
)
128 SYSLEVEL_ReleaseWin16Lock();
129 retval
= WaitForSingleObject( handle
, timeout
);
130 SYSLEVEL_RestoreWin16Lock();
135 /***********************************************************************
136 * WIN16_WaitForMultipleObjects (KERNEL.461)
138 DWORD WINAPI
WIN16_WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
139 BOOL wait_all
, DWORD timeout
)
143 SYSLEVEL_ReleaseWin16Lock();
144 retval
= WaitForMultipleObjects( count
, handles
, wait_all
, timeout
);
145 SYSLEVEL_RestoreWin16Lock();
150 /***********************************************************************
151 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
153 DWORD WINAPI
WIN16_WaitForMultipleObjectsEx( DWORD count
,
154 const HANDLE
*handles
,
155 BOOL wait_all
, DWORD timeout
,
160 SYSLEVEL_ReleaseWin16Lock();
161 retval
= WaitForMultipleObjectsEx( count
, handles
,
162 wait_all
, timeout
, alertable
);
163 SYSLEVEL_RestoreWin16Lock();