[fpc-devel] About GetTickCount

Sven Barth pascaldragon at googlemail.com
Thu Nov 3 21:47:15 CET 2011


Am 03.11.2011 18:15, schrieb Hans-Peter Diettrich:
> zeljko schrieb:
>
>> This is what MSDN says about GetTickCount:
>>
>> Retrieves the number of milliseconds that have elapsed since the
>> system was started, up to 49.7 days (what they do after 49.7 days ? ).
>
> When the DWORD overflows, Win9x stops to work properly. NT uses an
> bigger data type, at least internally.
>

It's basically a 64-bit type now. Here's ReactOS' implementation of 
GetTickCount64 (which is called by GetTickCount):

=== source begin ===

ULONGLONG
WINAPI
GetTickCount64(VOID)
{
     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)));
}

=== source end ===

You notice the loop regarding SharedUserData again? ;) (though this time 
it also contains a call to "YieldProcessor" and a comment regarding the 
loop)

By the way: the TickCount field (and also the SystemTime one) is a 
KSYSTEM_TIME struct which is defined like the following (copied from my 
port):

=== source begin ===

   //
   // System Time Structure
   //
   _KSYSTEM_TIME = packed record
     LowPart: ULONG;
     High1Time: LONG;
     High2Time: LONG;
   end;
   KSYSTEM_TIME = _KSYSTEM_TIME;
   PKSYSTEM_TIME = ^KSYSTEM_TIME;

=== source end ===

Regards,
Sven



More information about the fpc-devel mailing list