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 for (i
= 0; i
< count
; i
++)
90 TRACE(win32
,"handle %d is %08x\n",i
,handles
[i
]);
91 server_handle
[i
] = HANDLE_GetServerHandle( PROCESS_Current(), handles
[i
],
92 K32OBJ_UNKNOWN
, SYNCHRONIZE
);
93 if (server_handle
[i
] == -1)
95 ERR(win32
,"No server handle for %08x\n",handles
[i
] );
102 req
.timeout
= timeout
;
104 if (wait_all
) req
.flags
|= SELECT_ALL
;
105 if (alertable
) req
.flags
|= SELECT_ALERTABLE
;
106 if (timeout
!= INFINITE
) req
.flags
|= SELECT_TIMEOUT
;
108 CLIENT_SendRequest( REQ_SELECT
, -1, 2,
110 server_handle
, count
* sizeof(int) );
111 CLIENT_WaitReply( &len
, NULL
, 2, &reply
, sizeof(reply
),
113 if ((reply
.signaled
== STATUS_USER_APC
) && (len
> sizeof(reply
)))
116 len
-= sizeof(reply
);
117 for (i
= 0; i
< len
/ sizeof(void*); i
+= 2)
119 PAPCFUNC func
= (PAPCFUNC
)apc
[i
];
120 func( (ULONG_PTR
)apc
[i
+1] );
123 return reply
.signaled
;
127 /***********************************************************************
128 * WIN16_WaitForSingleObject (KERNEL.460)
130 DWORD WINAPI
WIN16_WaitForSingleObject( HANDLE handle
, DWORD timeout
)
134 SYSLEVEL_ReleaseWin16Lock();
135 retval
= WaitForSingleObject( handle
, timeout
);
136 SYSLEVEL_RestoreWin16Lock();
141 /***********************************************************************
142 * WIN16_WaitForMultipleObjects (KERNEL.461)
144 DWORD WINAPI
WIN16_WaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
145 BOOL wait_all
, DWORD timeout
)
149 SYSLEVEL_ReleaseWin16Lock();
150 retval
= WaitForMultipleObjects( count
, handles
, wait_all
, timeout
);
151 SYSLEVEL_RestoreWin16Lock();
156 /***********************************************************************
157 * WIN16_WaitForMultipleObjectsEx (KERNEL.495)
159 DWORD WINAPI
WIN16_WaitForMultipleObjectsEx( DWORD count
,
160 const HANDLE
*handles
,
161 BOOL wait_all
, DWORD timeout
,
166 SYSLEVEL_ReleaseWin16Lock();
167 retval
= WaitForMultipleObjectsEx( count
, handles
,
168 wait_all
, timeout
, alertable
);
169 SYSLEVEL_RestoreWin16Lock();