Changeset 46660 in webkit for trunk/JavaScriptCore/wtf/CurrentTime.cpp
- Timestamp:
- Jul 31, 2009, 10:26:11 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/CurrentTime.cpp
r44765 r46660 2 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 3 * Copyright (C) 2008 Google Inc. All rights reserved. 4 * Copyright (C) 2007-2009 Torch Mobile, Inc. 4 5 * 5 6 * Redistribution and use in source and binary forms, with or without … … 34 35 35 36 #if PLATFORM(WIN_OS) 37 36 38 // Windows is first since we want to use hires timers, despite PLATFORM(CF) 37 39 // being defined. … … 41 43 #include <math.h> 42 44 #include <stdint.h> 45 #include <time.h> 46 47 #if USE(QUERY_PERFORMANCE_COUNTER) 48 #if PLATFORM(WINCE) 49 extern "C" time_t mktime(struct tm *t); 50 #else 43 51 #include <sys/timeb.h> 44 52 #include <sys/types.h> 45 #include <time.h> 53 #endif 54 #endif 55 46 56 #elif PLATFORM(CF) 47 57 #include <CoreFoundation/CFDate.h> … … 59 69 60 70 #if PLATFORM(WIN_OS) 71 72 #if USE(QUERY_PERFORMANCE_COUNTER) 61 73 62 74 static LARGE_INTEGER qpcFrequency; … … 185 197 } 186 198 199 #else 200 201 static 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 224 double 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 187 248 #elif PLATFORM(CF) 188 249
Note:
See TracChangeset
for help on using the changeset viewer.