2 * Win32 process and thread synchronisation
4 * Copyright 1997 Alexandre Julliard
20 /***********************************************************************
21 * Sleep (KERNEL32.679)
23 VOID WINAPI
Sleep( DWORD timeout
)
25 WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, FALSE
);
28 /******************************************************************************
29 * SleepEx (KERNEL32.680)
31 DWORD WINAPI
SleepEx( DWORD timeout
, BOOL alertable
)
33 DWORD ret
= WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, alertable
);
34 if (ret
!= WAIT_IO_COMPLETION
) ret
= 0;
39 /***********************************************************************
40 * WaitForSingleObject (KERNEL32.723)
42 DWORD WINAPI
WaitForSingleObject( HANDLE handle
, DWORD timeout
)
44 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, FALSE
);
48 /***********************************************************************
49 * WaitForSingleObjectEx (KERNEL32.724)
51 DWORD WINAPI
WaitForSingleObjectEx( HANDLE handle
, DWORD timeout
,
54 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, alertable
);
58 /***********************************************************************
59 * WaitForMultipleObjects (KERNEL32.721)
61 DWORD WINAPI
WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
62 BOOL wait_all
, DWORD timeout
)
64 return WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
68 /***********************************************************************
69 * WaitForMultipleObjectsEx (KERNEL32.722)
71 DWORD WINAPI
WaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
,
72 BOOL wait_all
, DWORD timeout
,
75 struct select_request req
;
76 struct select_reply reply
;
77 int server_handle
[MAXIMUM_WAIT_OBJECTS
];
81 if (count
> MAXIMUM_WAIT_OBJECTS
)
83 SetLastError( ERROR_INVALID_PARAMETER
);
87 for (i
= 0; i
< count
; i
++) server_handle
[i
] = handles
[i
];
91 req
.timeout
= timeout
;
93 if (wait_all
) req
.flags
|= SELECT_ALL
;
94 if (alertable
) req
.flags
|= SELECT_ALERTABLE
;
95 if (timeout
!= INFINITE
) req
.flags
|= SELECT_TIMEOUT
;
97 CLIENT_SendRequest( REQ_SELECT
, -1, 2,
99 server_handle
, count
* sizeof(int) );
100 CLIENT_WaitReply( &len
, NULL
, 2, &reply
, sizeof(reply
),
102 if ((reply
.signaled
== STATUS_USER_APC
) && (len
> sizeof(reply
)))
105 len
-= sizeof(reply
);
106 for (i
= 0; i
< len
/ sizeof(void*); i
+= 2)
108 PAPCFUNC func
= (PAPCFUNC
)apc
[i
];
109 func( (ULONG_PTR
)apc
[i
+1] );
112 return reply
.signaled
;
116 /***********************************************************************
117 * WIN16_WaitForSingleObject (KERNEL.460)
119 DWORD WINAPI
WIN16_WaitForSingleObject( HANDLE handle
, DWORD timeout
)
123 SYSLEVEL_ReleaseWin16Lock();
124 retval
= WaitForSingleObject( handle
, timeout
);
125 SYSLEVEL_RestoreWin16Lock();
130 /***********************************************************************
131 * WIN16_WaitForMultipleObjects (KERNEL.461)
133 DWORD WINAPI
WIN16_WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
134 BOOL wait_all
, DWORD timeout
)
138 SYSLEVEL_ReleaseWin16Lock();
139 retval
= WaitForMultipleObjects( count
, handles
, wait_all
, timeout
);
140 SYSLEVEL_RestoreWin16Lock();
145 /***********************************************************************
146 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
148 DWORD WINAPI
WIN16_WaitForMultipleObjectsEx( DWORD count
,
149 const HANDLE
*handles
,
150 BOOL wait_all
, DWORD timeout
,
155 SYSLEVEL_ReleaseWin16Lock();
156 retval
= WaitForMultipleObjectsEx( count
, handles
,
157 wait_all
, timeout
, alertable
);
158 SYSLEVEL_RestoreWin16Lock();