Author: ion
Date: Sat Jul 23 11:05:00 2011
New Revision: 52798
URL:
http://svn.reactos.org/svn/reactos?rev=52798&view=rev
Log:
[KERNEL32]: Implement a BaseFormatTimeOut helper function to take care of
dwMillisecond->LARGE_INTEGER timeout conversion instead of duplicating 3 different
versions of the code required to do so.
Modified:
trunk/reactos/dll/win32/kernel32/client/debugger.c
trunk/reactos/dll/win32/kernel32/client/file/iocompl.c
trunk/reactos/dll/win32/kernel32/client/synch.c
trunk/reactos/dll/win32/kernel32/client/utils.c
trunk/reactos/dll/win32/kernel32/include/kernel32.h
Modified: trunk/reactos/dll/win32/kernel32/client/debugger.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/debugger.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/debugger.c [iso-8859-1] Sat Jul 23 11:05:00
2011
@@ -654,18 +654,8 @@
DBGUI_WAIT_STATE_CHANGE WaitStateChange;
NTSTATUS Status;
- /* Check if this is an infinite wait */
- if (dwMilliseconds == INFINITE)
- {
- /* Under NT, this means no timer argument */
- Timeout = NULL;
- }
- else
- {
- /* Otherwise, convert the time to NT Format */
- WaitTime.QuadPart = UInt32x32To64(-10000, dwMilliseconds);
- Timeout = &WaitTime;
- }
+ /* Convert to NT Timeout */
+ Timeout = BaseFormatTimeOut(&WaitTime, dwMilliseconds);
/* Loop while we keep getting interrupted */
do
Modified: trunk/reactos/dll/win32/kernel32/client/file/iocompl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/file/iocompl.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/file/iocompl.c [iso-8859-1] Sat Jul 23
11:05:00 2011
@@ -103,24 +103,23 @@
NTSTATUS errCode;
IO_STATUS_BLOCK IoStatus;
ULONG_PTR CompletionKey;
- LARGE_INTEGER Interval;
+ LARGE_INTEGER Time;
+ PLARGE_INTEGER TimePtr;
if (!lpNumberOfBytesTransferred || !lpCompletionKey || !lpOverlapped)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
-
- if (dwMilliseconds != INFINITE)
- {
- Interval.QuadPart = (-(MILLIS_TO_100NS(dwMilliseconds)));
- }
+
+ /* Convert the timeout */
+ TimePtr = BaseFormatTimeOut(&Time, dwMilliseconds);
errCode = NtRemoveIoCompletion(CompletionHandle,
(PVOID*)&CompletionKey,
(PVOID*)lpOverlapped,
&IoStatus,
- dwMilliseconds == INFINITE ? NULL : &Interval);
+ TimePtr);
if (!NT_SUCCESS(errCode) || errCode == STATUS_TIMEOUT) {
*lpOverlapped = NULL;
Modified: trunk/reactos/dll/win32/kernel32/client/synch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/synch.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/synch.c [iso-8859-1] Sat Jul 23 11:05:00 2011
@@ -49,18 +49,8 @@
hHandle = GetConsoleInputWaitHandle();
}
- /* Check if this is an infinite wait */
- if (dwMilliseconds == INFINITE)
- {
- /* Under NT, this means no timer argument */
- TimePtr = NULL;
- }
- else
- {
- /* Otherwise, convert the time to NT Format */
- Time.QuadPart = UInt32x32To64(-10000, dwMilliseconds);
- TimePtr = &Time;
- }
+ /* Convert the timeout */
+ TimePtr = BaseFormatTimeOut(&Time, dwMilliseconds);
/* Start wait loop */
do
@@ -151,18 +141,8 @@
}
}
- /* Check if this is an infinite wait */
- if (dwMilliseconds == INFINITE)
- {
- /* Under NT, this means no timer argument */
- TimePtr = NULL;
- }
- else
- {
- /* Otherwise, convert the time to NT Format */
- Time.QuadPart = UInt32x32To64(-10000, dwMilliseconds);
- TimePtr = &Time;
- }
+ /* Convert the timeout */
+ TimePtr = BaseFormatTimeOut(&Time, dwMilliseconds);
/* Start wait loop */
do
@@ -217,18 +197,8 @@
hObjectToWaitOn = GetConsoleInputWaitHandle();
}
- /* Check if this is an infinite wait */
- if (dwMilliseconds == INFINITE)
- {
- /* Under NT, this means no timer argument */
- TimePtr = NULL;
- }
- else
- {
- /* Otherwise, convert the time to NT Format */
- Time.QuadPart = UInt32x32To64(-10000, dwMilliseconds);
- TimePtr = &Time;
- }
+ /* Convert the timeout */
+ TimePtr = BaseFormatTimeOut(&Time, dwMilliseconds);
/* Start wait loop */
do
@@ -637,48 +607,51 @@
return TRUE;
}
-
-/*
- * @implemented
- */
-VOID WINAPI
-Sleep(DWORD dwMilliseconds)
-{
- SleepEx(dwMilliseconds, FALSE);
- return;
-}
-
-
-/*
- * @implemented
- */
-DWORD WINAPI
-SleepEx(DWORD dwMilliseconds,
- BOOL bAlertable)
-{
- LARGE_INTEGER Interval;
- NTSTATUS errCode;
-
- if (dwMilliseconds != INFINITE)
- {
- /*
- * System time units are 100 nanoseconds (a nanosecond is a billionth of
- * a second).
- */
- Interval.QuadPart = -((LONGLONG)dwMilliseconds * 10000);
- }
- else
- {
- /* Approximately 292000 years hence */
- Interval.QuadPart = -0x7FFFFFFFFFFFFFFFLL;
- }
-
-dowait:
- errCode = NtDelayExecution ((BOOLEAN)bAlertable, &Interval);
- if ((bAlertable) && (errCode == STATUS_ALERTED)) goto dowait;
- return (errCode == STATUS_USER_APC) ? WAIT_IO_COMPLETION : 0;
-}
-
+/*
+ * @implemented
+ */
+VOID
+WINAPI
+Sleep(IN DWORD dwMilliseconds)
+{
+ /* Call the new API */
+ SleepEx(dwMilliseconds, FALSE);
+}
+
+
+/*
+ * @implemented
+ */
+DWORD
+WINAPI
+SleepEx(IN DWORD dwMilliseconds,
+ IN BOOL bAlertable)
+{
+ LARGE_INTEGER Time;
+ PLARGE_INTEGER TimePtr;
+ NTSTATUS errCode;
+
+ /* Convert the timeout */
+ TimePtr = BaseFormatTimeOut(&Time, dwMilliseconds);
+ if (!TimePtr)
+ {
+ /* Turn an infinite wait into a really long wait */
+ Time.LowPart = 0;
+ Time.HighPart = 0x80000000;
+ TimePtr = &Time;
+ }
+
+ /* Loop the delay while APCs are alerting us */
+ do
+ {
+ /* Do the delay */
+ errCode = NtDelayExecution((BOOLEAN)bAlertable, TimePtr);
+ }
+ while ((bAlertable) && (errCode == STATUS_ALERTED));
+
+ /* Return the correct code */
+ return (errCode == STATUS_USER_APC) ? WAIT_IO_COMPLETION : 0;
+}
/*
* @implemented
Modified: trunk/reactos/dll/win32/kernel32/client/utils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/utils.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/utils.c [iso-8859-1] Sat Jul 23 11:05:00 2011
@@ -115,6 +115,19 @@
{
*UnicodeString = NULL;
}
+}
+
+PLARGE_INTEGER
+WINAPI
+BaseFormatTimeOut(OUT PLARGE_INTEGER Timeout,
+ IN DWORD dwMilliseconds)
+{
+ /* Check if this is an infinite wait, which means no timeout argument */
+ if (dwMilliseconds == INFINITE) return NULL;
+
+ /* Otherwise, convert the time to NT Format */
+ Timeout->QuadPart = UInt32x32To64(dwMilliseconds, -10000);
+ return Timeout;
}
/*
Modified: trunk/reactos/dll/win32/kernel32/include/kernel32.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/include…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/include/kernel32.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/include/kernel32.h [iso-8859-1] Sat Jul 23 11:05:00
2011
@@ -137,6 +137,11 @@
#define HeapFree RtlFreeHeap
#define _lread (_readfun)_hread
+PLARGE_INTEGER
+WINAPI
+BaseFormatTimeOut(OUT PLARGE_INTEGER Timeout,
+ IN DWORD dwMilliseconds);
+
POBJECT_ATTRIBUTES
WINAPI
BasepConvertObjectAttributes(OUT POBJECT_ATTRIBUTES ObjectAttributes,