X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/f9bf01c6616d5ddcf65b13b33cedf9e387ff7a63..14957cd040308e3eeec43d26bae5d76da13fcd85:/wtf/CurrentTime.cpp?ds=sidebyside diff --git a/wtf/CurrentTime.cpp b/wtf/CurrentTime.cpp index b272874..4205227 100644 --- a/wtf/CurrentTime.cpp +++ b/wtf/CurrentTime.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2006, 2010 Apple Inc. All rights reserved. * Copyright (C) 2008 Google Inc. All rights reserved. * Copyright (C) 2007-2009 Torch Mobile, Inc. * @@ -35,7 +35,7 @@ #if OS(WINDOWS) -// Windows is first since we want to use hires timers, despite PLATFORM(CF) +// Windows is first since we want to use hires timers, despite USE(CF) // being defined. // If defined, WIN32_LEAN_AND_MEAN disables timeBeginPeriod/timeEndPeriod. #undef WIN32_LEAN_AND_MEAN @@ -53,13 +53,13 @@ extern "C" time_t mktime(struct tm *t); #endif #endif -#elif PLATFORM(CF) -#include #elif PLATFORM(GTK) #include #elif PLATFORM(WX) #include -#else // Posix systems relying on the gettimeofday() +#elif PLATFORM(BREWMP) +#include +#else #include #endif @@ -163,7 +163,6 @@ double currentTime() // QueryPerformanceCounter has high resolution, but is only usable to measure time intervals. // To combine them, we call ftime and QueryPerformanceCounter initially. Later calls will use QueryPerformanceCounter // by itself, adding the delta to the saved ftime. We periodically re-sync to correct for drift. - static bool started; static double syncLowResUTCTime; static double syncHighResUpTime; static double lastUTCTime; @@ -249,13 +248,6 @@ double currentTime() #endif // USE(QUERY_PERFORMANCE_COUNTER) -#elif PLATFORM(CF) - -double currentTime() -{ - return CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970; -} - #elif PLATFORM(GTK) // Note: GTK on Windows will pick up the PLATFORM(WIN) implementation above which provides @@ -277,15 +269,27 @@ double currentTime() return (double)now.GetTicks() + (double)(now.GetMillisecond() / 1000.0); } -#else // Other Posix systems rely on the gettimeofday(). +#elif PLATFORM(BREWMP) +// GETUTCSECONDS returns the number of seconds since 1980/01/06 00:00:00 UTC, +// and GETTIMEMS returns the number of milliseconds that have elapsed since the last +// occurrence of 00:00:00 local time. +// We can combine GETUTCSECONDS and GETTIMEMS to calculate the number of milliseconds +// since 1970/01/01 00:00:00 UTC. double currentTime() { - struct timeval now; - struct timezone zone; + // diffSeconds is the number of seconds from 1970/01/01 to 1980/01/06 + const unsigned diffSeconds = 315964800; + return static_cast(diffSeconds + GETUTCSECONDS() + ((GETTIMEMS() % 1000) / msPerSecond)); +} + +#else - gettimeofday(&now, &zone); - return static_cast(now.tv_sec) + (double)(now.tv_usec / 1000000.0); +double currentTime() +{ + struct timeval now; + gettimeofday(&now, 0); + return now.tv_sec + now.tv_usec / 1000000.0; } #endif