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];
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;
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
,
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
,
94 struct select_request
*req
= get_req_buffer();
97 if (count
> MAXIMUM_WAIT_OBJECTS
)
99 SetLastError( ERROR_INVALID_PARAMETER
);
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();
118 /***********************************************************************
119 * WIN16_WaitForSingleObject (KERNEL.460)
121 DWORD WINAPI
WIN16_WaitForSingleObject( HANDLE handle
, DWORD timeout
)
125 SYSLEVEL_ReleaseWin16Lock();
126 retval
= WaitForSingleObject( handle
, timeout
);
127 SYSLEVEL_RestoreWin16Lock();
132 /***********************************************************************
133 * WIN16_WaitForMultipleObjects (KERNEL.461)
135 DWORD WINAPI
WIN16_WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
136 BOOL wait_all
, DWORD timeout
)
140 SYSLEVEL_ReleaseWin16Lock();
141 retval
= WaitForMultipleObjects( count
, handles
, wait_all
, timeout
);
142 SYSLEVEL_RestoreWin16Lock();
147 /***********************************************************************
148 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
150 DWORD WINAPI
WIN16_WaitForMultipleObjectsEx( DWORD count
,
151 const HANDLE
*handles
,
152 BOOL wait_all
, DWORD timeout
,
157 SYSLEVEL_ReleaseWin16Lock();
158 retval
= WaitForMultipleObjectsEx( count
, handles
,
159 wait_all
, timeout
, alertable
);
160 SYSLEVEL_RestoreWin16Lock();