2 * Win32 process and thread synchronisation
4 * Copyright 1997 Alexandre Julliard
12 #include "file.h" /* for DOSFS_UnixTimeToFileTime */
18 /***********************************************************************
21 * Call outstanding APCs.
23 static void call_apcs(void)
34 struct get_apc_request
*req
= server_alloc_req( sizeof(*req
), sizeof(args
) );
35 if (!server_call( REQ_GET_APC
))
39 memcpy( args
, server_data_ptr(req
), server_data_size(req
) );
47 return; /* no more APCs */
55 /* convert sec/usec to NT time */
56 DOSFS_UnixTimeToFileTime( (time_t)args
[0], &ft
, (DWORD
)args
[1] * 10 );
57 proc( args
[2], ft
.dwLowDateTime
, ft
.dwHighDateTime
);
60 server_protocol_error( "get_apc_request: bad type %d\n", type
);
66 /***********************************************************************
67 * Sleep (KERNEL32.679)
69 VOID WINAPI
Sleep( DWORD timeout
)
71 WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, FALSE
);
74 /******************************************************************************
75 * SleepEx (KERNEL32.680)
77 DWORD WINAPI
SleepEx( DWORD timeout
, BOOL alertable
)
79 DWORD ret
= WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, alertable
);
80 if (ret
!= WAIT_IO_COMPLETION
) ret
= 0;
85 /***********************************************************************
86 * WaitForSingleObject (KERNEL32.723)
88 DWORD WINAPI
WaitForSingleObject( HANDLE handle
, DWORD timeout
)
90 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, FALSE
);
94 /***********************************************************************
95 * WaitForSingleObjectEx (KERNEL32.724)
97 DWORD WINAPI
WaitForSingleObjectEx( HANDLE handle
, DWORD timeout
,
100 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, alertable
);
104 /***********************************************************************
105 * WaitForMultipleObjects (KERNEL32.721)
107 DWORD WINAPI
WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
108 BOOL wait_all
, DWORD timeout
)
110 return WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
114 /***********************************************************************
115 * WaitForMultipleObjectsEx (KERNEL32.722)
117 DWORD WINAPI
WaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
,
118 BOOL wait_all
, DWORD timeout
,
123 if (count
> MAXIMUM_WAIT_OBJECTS
)
125 SetLastError( ERROR_INVALID_PARAMETER
);
131 struct select_request
*req
= server_alloc_req( sizeof(*req
), count
* sizeof(int) );
132 int *data
= server_data_ptr( req
);
135 req
->timeout
= timeout
;
136 for (i
= 0; i
< count
; i
++) data
[i
] = handles
[i
];
138 if (wait_all
) req
->flags
|= SELECT_ALL
;
139 if (alertable
) req
->flags
|= SELECT_ALERTABLE
;
140 if (timeout
!= INFINITE
) req
->flags
|= SELECT_TIMEOUT
;
142 server_call( REQ_SELECT
);
146 if (ret
== STATUS_USER_APC
) call_apcs();
151 /***********************************************************************
152 * WIN16_WaitForSingleObject (KERNEL.460)
154 DWORD WINAPI
WIN16_WaitForSingleObject( HANDLE handle
, DWORD timeout
)
156 DWORD retval
, mutex_count
;
158 ReleaseThunkLock( &mutex_count
);
159 retval
= WaitForSingleObject( handle
, timeout
);
160 RestoreThunkLock( mutex_count
);
164 /***********************************************************************
165 * WIN16_WaitForMultipleObjects (KERNEL.461)
167 DWORD WINAPI
WIN16_WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
168 BOOL wait_all
, DWORD timeout
)
170 DWORD retval
, mutex_count
;
172 ReleaseThunkLock( &mutex_count
);
173 retval
= WaitForMultipleObjects( count
, handles
, wait_all
, timeout
);
174 RestoreThunkLock( mutex_count
);
178 /***********************************************************************
179 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
181 DWORD WINAPI
WIN16_WaitForMultipleObjectsEx( DWORD count
,
182 const HANDLE
*handles
,
183 BOOL wait_all
, DWORD timeout
,
186 DWORD retval
, mutex_count
;
188 ReleaseThunkLock( &mutex_count
);
189 retval
= WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, alertable
);
190 RestoreThunkLock( mutex_count
);