- NtUserWaitForInputIdle: Call EngGetTickCount, removing duplicated code
authorStefan Ginsberg <stefanginsberg@gmail.com>
Tue, 6 Jan 2009 19:57:44 +0000 (19:57 +0000)
committerStefan Ginsberg <stefanginsberg@gmail.com>
Tue, 6 Jan 2009 19:57:44 +0000 (19:57 +0000)
- GetTickCount/GetTickCount64/EngGetTickCount: Use the correct SharedUserData fields, and fix the calculations
- KeUpdateSystemTime: Don't update TickCountLowDeprecated now that it truly is deprecated
- Thanks to Fireball and KJK!

svn path=/trunk/; revision=38616

reactos/dll/win32/kernel32/misc/time.c
reactos/ntoskrnl/ke/i386/systimer.S
reactos/ntoskrnl/ke/powerpc/ppc_irq.c
reactos/subsystems/win32/win32k/ntuser/message.c
reactos/subsystems/win32/win32k/stubs/stubs.c

index 32d1d17..65ed5e9 100644 (file)
@@ -578,7 +578,8 @@ DWORD
 WINAPI
 GetTickCount(VOID)
 {
-    return (DWORD)((ULONGLONG)SharedUserData->TickCountLowDeprecated * SharedUserData->TickCountMultiplier / 16777216);
+    /* Call the 64-bit version */
+    return (DWORD)GetTickCount64();
 }
 
 
@@ -589,7 +590,25 @@ ULONGLONG
 WINAPI
 GetTickCount64(VOID)
 {
-    return (ULONGLONG)SharedUserData->TickCountLowDeprecated * (ULONGLONG)SharedUserData->TickCountMultiplier / 16777216;
+    ULONG Multiplier;
+    LARGE_INTEGER TickCount;
+
+    /* Loop until we get a perfect match */
+    for (;;)
+    {
+        /* Read the tick count value */
+        TickCount.HighPart = SharedUserData->TickCount.High1Time;
+        TickCount.LowPart = SharedUserData->TickCount.LowPart;
+        if (TickCount.HighPart == SharedUserData->TickCount.High2Time) break;
+        YieldProcessor();
+    }
+
+    /* Get the multiplier */
+    Multiplier = SharedUserData->TickCountMultiplier;
+
+    /* Convert to milliseconds and return */
+    return (Int64ShrlMod32(UInt32x32To64(Multiplier, TickCount.LowPart), 24) +
+            (Multiplier * (TickCount.HighPart << 8)));
 }
 
 
index e4ce20d..f196971 100644 (file)
@@ -294,9 +294,6 @@ _KeUpdateSystemTime@0:
     mov ds:[USER_SHARED_DATA+USER_SHARED_DATA_TICK_COUNT], ecx
     mov ds:[USER_SHARED_DATA+USER_SHARED_DATA_TICK_COUNT+4], edx
 
-    /* FIXME: HACK */
-    mov ds:[USER_SHARED_DATA], ecx
-
     /* Get hand index and entry into the table */
     and eax, TIMER_TABLE_SIZE - 1
     shl eax, 4
index aa30548..f4b1b82 100644 (file)
@@ -349,9 +349,6 @@ KeUpdateSystemTime(IN PKTRAP_FRAME TrapFrame,
         SharedUserData->TickCount.LowPart = Time.LowPart;\r
         SharedUserData->TickCount.High1Time = Time.HighPart;\r
 \r
-        /* Update tick count in shared user data as well */\r
-        SharedUserData->TickCountLowDeprecated++;\r
-\r
         /* Queue a DPC that will expire timers */\r
         KeInsertQueueDpc(&KiExpireTimerDpc, 0, 0);\r
     }\r
index 5949a63..2f23df4 100644 (file)
@@ -2239,8 +2239,7 @@ NtUserWaitForInputIdle(
       return STATUS_SUCCESS;  /* no event to wait on */
   }
 
-  StartTime = ((ULONGLONG)SharedUserData->TickCountLowDeprecated *
-                          SharedUserData->TickCountMultiplier / 16777216);
+  StartTime = EngGetTickCount();
 
   Run = dwMilliseconds;
 
@@ -2294,9 +2293,7 @@ NtUserWaitForInputIdle(
 
      if (dwMilliseconds != INFINITE)
      {
-        Elapsed = ((ULONGLONG)SharedUserData->TickCountLowDeprecated *
-                              SharedUserData->TickCountMultiplier / 16777216)
-                              - StartTime;
+        Elapsed = EngGetTickCount() - StartTime;
 
         if (Elapsed > Run)
            Status = STATUS_TIMEOUT;
index 70f9efb..96f0736 100644 (file)
@@ -2888,12 +2888,21 @@ EngFreeSectionMem(IN PVOID SectionObject OPTIONAL,
     UNIMPLEMENTED;
     return FALSE;
 }
+
 ULONGLONG
 APIENTRY
 EngGetTickCount(VOID)
 {
- return ((ULONGLONG)SharedUserData->TickCountLowDeprecated * SharedUserData->TickCountMultiplier / 16777216);
+    ULONG Multiplier;
+    LARGE_INTEGER TickCount;
+
+    /* Get the multiplier and current tick count */
+    KeQueryTickCount(&TickCount);
+    Multiplier = SharedUserData->TickCountMultiplier;
+
+    /* Convert to milliseconds and return */
+    return (Int64ShrlMod32(UInt32x32To64(Multiplier, TickCount.LowPart), 24) +
+            (Multiplier * (TickCount.HighPart << 8)));
 }
  
 BOOLEAN