summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/wtf/CurrentTime.cpp
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2009-08-11 17:01:47 +0100
committerBen Murdoch <benm@google.com>2009-08-11 18:21:02 +0100
commit0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5 (patch)
tree2943df35f62d885c89d01063cc528dd73b480fea /JavaScriptCore/wtf/CurrentTime.cpp
parent7e7a70bfa49a1122b2597a1e6367d89eb4035eca (diff)
downloadexternal_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.zip
external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.gz
external_webkit-0bf48ef3be53ddaa52bbead65dfd75bf90e7a2b5.tar.bz2
Merge in WebKit r47029.
Diffstat (limited to 'JavaScriptCore/wtf/CurrentTime.cpp')
-rw-r--r--JavaScriptCore/wtf/CurrentTime.cpp69
1 files changed, 65 insertions, 4 deletions
diff --git a/JavaScriptCore/wtf/CurrentTime.cpp b/JavaScriptCore/wtf/CurrentTime.cpp
index 74984c1..45c724a 100644
--- a/JavaScriptCore/wtf/CurrentTime.cpp
+++ b/JavaScriptCore/wtf/CurrentTime.cpp
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
* Copyright (C) 2008 Google Inc. All rights reserved.
+ * Copyright (C) 2007-2009 Torch Mobile, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -33,6 +34,7 @@
#include "CurrentTime.h"
#if PLATFORM(WIN_OS)
+
// Windows is first since we want to use hires timers, despite PLATFORM(CF)
// being defined.
// If defined, WIN32_LEAN_AND_MEAN disables timeBeginPeriod/timeEndPeriod.
@@ -40,9 +42,17 @@
#include <windows.h>
#include <math.h>
#include <stdint.h>
+#include <time.h>
+
+#if USE(QUERY_PERFORMANCE_COUNTER)
+#if PLATFORM(WINCE)
+extern "C" time_t mktime(struct tm *t);
+#else
#include <sys/timeb.h>
#include <sys/types.h>
-#include <time.h>
+#endif
+#endif
+
#elif PLATFORM(CF)
#include <CoreFoundation/CFDate.h>
#elif PLATFORM(GTK)
@@ -59,6 +69,8 @@ const double msPerSecond = 1000.0;
#if PLATFORM(WIN_OS)
+#if USE(QUERY_PERFORMANCE_COUNTER)
+
static LARGE_INTEGER qpcFrequency;
static bool syncedTime;
@@ -107,7 +119,7 @@ static double highResUpTime()
static double lowResUTCTime()
{
-#if PLATFORM(WIN_CE)
+#if PLATFORM(WINCE)
SYSTEMTIME systemTime;
GetSystemTime(&systemTime);
struct tm tmtime;
@@ -120,11 +132,11 @@ static double lowResUTCTime()
tmtime.tm_sec = systemTime.wSecond;
time_t timet = mktime(&tmtime);
return timet * msPerSecond + systemTime.wMilliseconds;
-#else // PLATFORM(WIN_CE)
+#else
struct _timeb timebuffer;
_ftime(&timebuffer);
return timebuffer.time * msPerSecond + timebuffer.millitm;
-#endif // PLATFORM(WIN_CE)
+#endif
}
static bool qpcAvailable()
@@ -184,6 +196,55 @@ double currentTime()
return utc / 1000.0;
}
+#else
+
+static double currentSystemTime()
+{
+ FILETIME ft;
+ GetCurrentFT(&ft);
+
+ // As per Windows documentation for FILETIME, copy the resulting FILETIME structure to a
+ // ULARGE_INTEGER structure using memcpy (using memcpy instead of direct assignment can
+ // prevent alignment faults on 64-bit Windows).
+
+ ULARGE_INTEGER t;
+ memcpy(&t, &ft, sizeof(t));
+
+ // Windows file times are in 100s of nanoseconds.
+ // To convert to seconds, we have to divide by 10,000,000, which is more quickly
+ // done by multiplying by 0.0000001.
+
+ // Between January 1, 1601 and January 1, 1970, there were 369 complete years,
+ // of which 89 were leap years (1700, 1800, and 1900 were not leap years).
+ // That is a total of 134774 days, which is 11644473600 seconds.
+
+ return t.QuadPart * 0.0000001 - 11644473600.0;
+}
+
+double currentTime()
+{
+ static bool init = false;
+ static double lastTime;
+ static DWORD lastTickCount;
+ if (!init) {
+ lastTime = currentSystemTime();
+ lastTickCount = GetTickCount();
+ init = true;
+ return lastTime;
+ }
+
+ DWORD tickCountNow = GetTickCount();
+ DWORD elapsed = tickCountNow - lastTickCount;
+ double timeNow = lastTime + (double)elapsed / 1000.;
+ if (elapsed >= 0x7FFFFFFF) {
+ lastTime = timeNow;
+ lastTickCount = tickCountNow;
+ }
+ return timeNow;
+}
+
+#endif // USE(QUERY_PERFORMANCE_COUNTER)
+
#elif PLATFORM(CF)
double currentTime()