2 * Win32 process and thread synchronisation
4 * Copyright 1997 Alexandre Julliard
21 /***********************************************************************
22 * Sleep (KERNEL32.679)
24 VOID WINAPI
Sleep( DWORD timeout
)
26 WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, FALSE
);
29 /******************************************************************************
30 * SleepEx (KERNEL32.680)
32 DWORD WINAPI
SleepEx( DWORD timeout
, BOOL alertable
)
34 DWORD ret
= WaitForMultipleObjectsEx( 0, NULL
, FALSE
, timeout
, alertable
);
35 if (ret
!= WAIT_IO_COMPLETION
) ret
= 0;
40 /***********************************************************************
41 * WaitForSingleObject (KERNEL32.723)
43 DWORD WINAPI
WaitForSingleObject( HANDLE handle
, DWORD timeout
)
45 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, FALSE
);
49 /***********************************************************************
50 * WaitForSingleObjectEx (KERNEL32.724)
52 DWORD WINAPI
WaitForSingleObjectEx( HANDLE handle
, DWORD timeout
,
55 return WaitForMultipleObjectsEx( 1, &handle
, FALSE
, timeout
, alertable
);
59 /***********************************************************************
60 * WaitForMultipleObjects (KERNEL32.721)
62 DWORD WINAPI
WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
63 BOOL wait_all
, DWORD timeout
)
65 return WaitForMultipleObjectsEx( count
, handles
, wait_all
, timeout
, FALSE
);
69 /***********************************************************************
70 * WaitForMultipleObjectsEx (KERNEL32.722)
72 DWORD WINAPI
WaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
,
73 BOOL wait_all
, DWORD timeout
,
76 struct select_request req
;
77 struct select_reply reply
;
78 int server_handle
[MAXIMUM_WAIT_OBJECTS
];
82 if (count
> MAXIMUM_WAIT_OBJECTS
)
84 SetLastError( ERROR_INVALID_PARAMETER
);
88 /* FIXME: This is extremely ugly, but needed to avoid endless
89 * recursion due to EVENT_Synchronize itself using
90 * EnterCriticalSection( &X11DRV_CritSection ) ...
92 if ( count
== 0 || handles
[0] != X11DRV_CritSection
.LockSemaphore
)
94 /* Before we might possibly block, we need to push outstanding
95 * graphics output to the X server ... This needs to be done
96 * here so that it also works with native USER.
99 EVENT_Synchronize( FALSE
);
102 for (i
= 0; i
< count
; i
++) server_handle
[i
] = handles
[i
];
106 req
.timeout
= timeout
;
108 if (wait_all
) req
.flags
|= SELECT_ALL
;
109 if (alertable
) req
.flags
|= SELECT_ALERTABLE
;
110 if (timeout
!= INFINITE
) req
.flags
|= SELECT_TIMEOUT
;
112 CLIENT_SendRequest( REQ_SELECT
, -1, 2,
114 server_handle
, count
* sizeof(int) );
115 CLIENT_WaitReply( &len
, NULL
, 2, &reply
, sizeof(reply
),
117 if ((reply
.signaled
== STATUS_USER_APC
) && (len
> sizeof(reply
)))
120 len
-= sizeof(reply
);
121 for (i
= 0; i
< len
/ sizeof(void*); i
+= 2)
123 PAPCFUNC func
= (PAPCFUNC
)apc
[i
];
124 if ( func
) func( (ULONG_PTR
)apc
[i
+1] );
127 return reply
.signaled
;
131 /***********************************************************************
132 * WIN16_WaitForSingleObject (KERNEL.460)
134 DWORD WINAPI
WIN16_WaitForSingleObject( HANDLE handle
, DWORD timeout
)
138 SYSLEVEL_ReleaseWin16Lock();
139 retval
= WaitForSingleObject( handle
, timeout
);
140 SYSLEVEL_RestoreWin16Lock();
145 /***********************************************************************
146 * WIN16_WaitForMultipleObjects (KERNEL.461)
148 DWORD WINAPI
WIN16_WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
149 BOOL wait_all
, DWORD timeout
)
153 SYSLEVEL_ReleaseWin16Lock();
154 retval
= WaitForMultipleObjects( count
, handles
, wait_all
, timeout
);
155 SYSLEVEL_RestoreWin16Lock();
160 /***********************************************************************
161 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
163 DWORD WINAPI
WIN16_WaitForMultipleObjectsEx( DWORD count
,
164 const HANDLE
*handles
,
165 BOOL wait_all
, DWORD timeout
,
170 SYSLEVEL_ReleaseWin16Lock();
171 retval
= WaitForMultipleObjectsEx( count
, handles
,
172 wait_all
, timeout
, alertable
);
173 SYSLEVEL_RestoreWin16Lock();