mirror of
https://github.com/reactos/reactos.git
synced 2025-07-13 10:14:13 +00:00
[TIMEOUT]: Use a waitable timer to wait for a maximum of 1 second, instead of using some Sleep(100) calls. The only Sleep() call allowed is the Sleep(INFINITE) one.
svn path=/trunk/; revision=75977
This commit is contained in:
parent
036a0ad651
commit
4bce7ced02
1 changed files with 43 additions and 3 deletions
|
@ -49,6 +49,7 @@ INT InputWait(BOOL bNoBreak, INT timerValue)
|
||||||
INT Status = EXIT_SUCCESS;
|
INT Status = EXIT_SUCCESS;
|
||||||
HANDLE hInput;
|
HANDLE hInput;
|
||||||
BOOL bUseTimer = (timerValue != -1);
|
BOOL bUseTimer = (timerValue != -1);
|
||||||
|
HANDLE hTimer = NULL;
|
||||||
DWORD dwStartTime;
|
DWORD dwStartTime;
|
||||||
LONG timeElapsed;
|
LONG timeElapsed;
|
||||||
DWORD dwWaitState;
|
DWORD dwWaitState;
|
||||||
|
@ -67,6 +68,16 @@ INT InputWait(BOOL bNoBreak, INT timerValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start a new wait if we use the timer */
|
/* Start a new wait if we use the timer */
|
||||||
|
if (bNoBreak && bUseTimer)
|
||||||
|
{
|
||||||
|
hTimer = CreateWaitableTimer(NULL, TRUE, NULL);
|
||||||
|
if (hTimer == NULL)
|
||||||
|
{
|
||||||
|
/* A problem happened, bail out */
|
||||||
|
PrintError(GetLastError());
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (bUseTimer)
|
if (bUseTimer)
|
||||||
dwStartTime = GetTickCount();
|
dwStartTime = GetTickCount();
|
||||||
|
|
||||||
|
@ -138,8 +149,34 @@ INT InputWait(BOOL bNoBreak, INT timerValue)
|
||||||
{
|
{
|
||||||
if (bUseTimer)
|
if (bUseTimer)
|
||||||
{
|
{
|
||||||
/* We use the timer: wait a little bit before updating it */
|
LARGE_INTEGER DueTime;
|
||||||
Sleep(100);
|
|
||||||
|
/* We use the timer: use a passive wait of maximum 1 second */
|
||||||
|
timeElapsed = GetTickCount() - dwStartTime;
|
||||||
|
if (timeElapsed < 1000)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* For whatever reason, x86 MSVC generates a ntdll!_allmul
|
||||||
|
* call when using Int32x32To64(), instead of an imul
|
||||||
|
* instruction. This leads the linker to error that _allmul
|
||||||
|
* is missing, since we do not link against ntdll.
|
||||||
|
* Everything is however OK with GCC...
|
||||||
|
* We therefore use the __emul() intrinsic which does
|
||||||
|
* the correct job.
|
||||||
|
*/
|
||||||
|
DueTime.QuadPart = __emul(1000 - timeElapsed, -10000);
|
||||||
|
SetWaitableTimer(hTimer, &DueTime, 0, NULL, NULL, FALSE);
|
||||||
|
dwWaitState = WaitForSingleObject(hTimer, INFINITE);
|
||||||
|
|
||||||
|
/* Check whether the timer has been signaled */
|
||||||
|
if (dwWaitState != WAIT_OBJECT_0)
|
||||||
|
{
|
||||||
|
/* An error happened, bail out */
|
||||||
|
PrintError(GetLastError());
|
||||||
|
Status = EXIT_FAILURE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -170,7 +207,7 @@ INT InputWait(BOOL bNoBreak, INT timerValue)
|
||||||
else
|
else
|
||||||
dwWaitState = WAIT_TIMEOUT;
|
dwWaitState = WAIT_TIMEOUT;
|
||||||
|
|
||||||
/* Check whether the input handle has been signaled, or a timeout happened */
|
/* Check whether the input event has been signaled, or a timeout happened */
|
||||||
if (dwWaitState == WAIT_TIMEOUT)
|
if (dwWaitState == WAIT_TIMEOUT)
|
||||||
continue;
|
continue;
|
||||||
if (dwWaitState != WAIT_OBJECT_0)
|
if (dwWaitState != WAIT_OBJECT_0)
|
||||||
|
@ -235,6 +272,9 @@ Quit:
|
||||||
if (bNoBreak)
|
if (bNoBreak)
|
||||||
SetConsoleCtrlHandler(NULL, FALSE);
|
SetConsoleCtrlHandler(NULL, FALSE);
|
||||||
|
|
||||||
|
if (bNoBreak && bUseTimer)
|
||||||
|
CloseHandle(hTimer);
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue