Ignore:
Timestamp:
Jul 31, 2009, 10:26:11 PM (16 years ago)
Author:
[email protected]
Message:

2009-07-31 Yong Li <[email protected]>

Reviewed by George Staikos.

Resurrect the old GetTickCount implementation of currentTime, controlled by WTF_USE_QUERY_PERFORMANCE_COUNTER
currentSystemTime taken from older WebKit; currentTime written by Yong Li <[email protected]>; cleanup by Joe Mason <[email protected]>
https://bugs.webkit.org/show_bug.cgi?id=27848

  • wtf/CurrentTime.cpp: (WTF::currentSystemTime): get current time with GetCurrentFT (WTF::currentTime): track msec elapsed since first currentSystemTime call using GetTickCount
  • wtf/Platform.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/CurrentTime.cpp

    r44765 r46660  
    22 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
    33 * Copyright (C) 2008 Google Inc. All rights reserved.
     4 * Copyright (C) 2007-2009 Torch Mobile, Inc.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    3435
    3536#if PLATFORM(WIN_OS)
     37
    3638// Windows is first since we want to use hires timers, despite PLATFORM(CF)
    3739// being defined.
     
    4143#include <math.h>
    4244#include <stdint.h>
     45#include <time.h>
     46
     47#if USE(QUERY_PERFORMANCE_COUNTER)
     48#if PLATFORM(WINCE)
     49extern "C" time_t mktime(struct tm *t);
     50#else
    4351#include <sys/timeb.h>
    4452#include <sys/types.h>
    45 #include <time.h>
     53#endif
     54#endif
     55
    4656#elif PLATFORM(CF)
    4757#include <CoreFoundation/CFDate.h>
     
    5969
    6070#if PLATFORM(WIN_OS)
     71
     72#if USE(QUERY_PERFORMANCE_COUNTER)
    6173
    6274static LARGE_INTEGER qpcFrequency;
     
    185197}
    186198
     199#else
     200
     201static double currentSystemTime()
     202{
     203    FILETIME ft;
     204    GetCurrentFT(&ft);
     205
     206    // As per Windows documentation for FILETIME, copy the resulting FILETIME structure to a
     207    // ULARGE_INTEGER structure using memcpy (using memcpy instead of direct assignment can
     208    // prevent alignment faults on 64-bit Windows).
     209
     210    ULARGE_INTEGER t;
     211    memcpy(&t, &ft, sizeof(t));
     212
     213    // Windows file times are in 100s of nanoseconds.
     214    // To convert to seconds, we have to divide by 10,000,000, which is more quickly
     215    // done by multiplying by 0.0000001.
     216
     217    // Between January 1, 1601 and January 1, 1970, there were 369 complete years,
     218    // of which 89 were leap years (1700, 1800, and 1900 were not leap years).
     219    // That is a total of 134774 days, which is 11644473600 seconds.
     220
     221    return t.QuadPart * 0.0000001 - 11644473600.0;
     222}
     223
     224double currentTime()
     225{
     226    static bool init = false;
     227    static double lastTime;
     228    static DWORD lastTickCount;
     229    if (!init) {
     230        lastTime = currentSystemTime();
     231        lastTickCount = GetTickCount();
     232        init = true;
     233        return lastTime;
     234    }
     235
     236    DWORD tickCountNow = GetTickCount();
     237    DWORD elapsed = tickCountNow - lastTickCount;
     238    double timeNow = lastTime + (double)elapsed / 1000.;
     239    if (elapsed >= 0x7FFFFFFF) {
     240        lastTime = timeNow;
     241        lastTickCount = tickCountNow;
     242    }
     243    return timeNow;
     244}
     245
     246#endif // USE(QUERY_PERFORMANCE_COUNTER)
     247
    187248#elif PLATFORM(CF)
    188249
Note: See TracChangeset for help on using the changeset viewer.