2 * Win32 process and thread synchronisation
4 * Copyright 1997 Alexandre Julliard
12 #include "file.h" /* for DOSFS_UnixTimeToFileTime */
19 /***********************************************************************
22 * Call outstanding APCs.
24 static void call_apcs(void)
35 struct get_apc_request
*req
= server_alloc_req( sizeof(*req
), sizeof(args
) );
36 if (!server_call( REQ_GET_APC
))
40 memcpy( args
, server_data_ptr(req
), server_data_size(req
) );
48 return; /* no more APCs */
56 /* convert sec/usec to NT time */
57 DOSFS_UnixTimeToFileTime( (time_t)args
[0], &ft
, (DWORD
)args
[1] * 10 );
58 proc( args
[2], ft
.dwLowDateTime
, ft
.dwHighDateTime
);
61 server_protocol_error( "get_apc_request: bad type %d\n", type
);
67 /***********************************************************************
68 * Sleep (KERNEL32.679)
70 VOID WINAPI
Sleep( DWORD timeout
)
72 WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, FALSE
);
75 /******************************************************************************
76 * SleepEx (KERNEL32.680)
78 DWORD WINAPI
SleepEx( DWORD timeout
, BOOL alertable
)
80 DWORD ret
= WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, alertable
);
81 if (ret
!= WAIT_IO_COMPLETION
) ret
= 0;
86 /***********************************************************************
87 * WaitForSingleObject (KERNEL32.723)
89 DWORD WINAPI
WaitForSingleObject( HANDLE handle
, DWORD timeout
)
91 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, FALSE
);
95 /***********************************************************************
96 * WaitForSingleObjectEx (KERNEL32.724)
98 DWORD WINAPI
WaitForSingleObjectEx( HANDLE handle
, DWORD timeout
,
101 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, alertable
);
105 /***********************************************************************
106 * WaitForMultipleObjects (KERNEL32.721)
108 DWORD WINAPI
WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
109 BOOL wait_all
, DWORD timeout
)
111 return WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
115 /***********************************************************************
116 * WaitForMultipleObjectsEx (KERNEL32.722)
118 DWORD WINAPI
WaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
,
119 BOOL wait_all
, DWORD timeout
,
124 if (count
> MAXIMUM_WAIT_OBJECTS
)
126 SetLastError( ERROR_INVALID_PARAMETER
);
132 struct select_request
*req
= server_alloc_req( sizeof(*req
), count
* sizeof(int) );
133 int *data
= server_data_ptr( req
);
136 req
->timeout
= timeout
;
137 for (i
= 0; i
< count
; i
++) data
[i
] = handles
[i
];
139 if (wait_all
) req
->flags
|= SELECT_ALL
;
140 if (alertable
) req
->flags
|= SELECT_ALERTABLE
;
141 if (timeout
!= INFINITE
) req
->flags
|= SELECT_TIMEOUT
;
143 server_call( REQ_SELECT
);
147 if (ret
== STATUS_USER_APC
) call_apcs();
152 /***********************************************************************
153 * WIN16_WaitForSingleObject (KERNEL.460)
155 DWORD WINAPI
WIN16_WaitForSingleObject( HANDLE handle
, DWORD timeout
)
159 SYSLEVEL_ReleaseWin16Lock();
160 retval
= WaitForSingleObject( handle
, timeout
);
161 SYSLEVEL_RestoreWin16Lock();
166 /***********************************************************************
167 * WIN16_WaitForMultipleObjects (KERNEL.461)
169 DWORD WINAPI
WIN16_WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
170 BOOL wait_all
, DWORD timeout
)
174 SYSLEVEL_ReleaseWin16Lock();
175 retval
= WaitForMultipleObjects( count
, handles
, wait_all
, timeout
);
176 SYSLEVEL_RestoreWin16Lock();
181 /***********************************************************************
182 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
184 DWORD WINAPI
WIN16_WaitForMultipleObjectsEx( DWORD count
,
185 const HANDLE
*handles
,
186 BOOL wait_all
, DWORD timeout
,
191 SYSLEVEL_ReleaseWin16Lock();
192 retval
= WaitForMultipleObjectsEx( count
, handles
,
193 wait_all
, timeout
, alertable
);
194 SYSLEVEL_RestoreWin16Lock();