Adding a high-resolution timer to platform win32.
authorjkummerow@chromium.org <jkummerow@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 2 Oct 2012 10:59:44 +0000 (10:59 +0000)
committerjkummerow@chromium.org <jkummerow@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 2 Oct 2012 10:59:44 +0000 (10:59 +0000)
BUG=None

Review URL: https://codereview.chromium.org/10867057
Patch from Sergey Rogulenko <rogulenko@google.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12651 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/platform-win32.cc

index 65d31a9..f9e37d8 100644 (file)
@@ -591,8 +591,16 @@ double OS::TimeCurrentMillis() {
   return t.ToJSTime();
 }
 
-// Returns the tickcounter based on timeGetTime.
+
+static LARGE_INTEGER frequency = 0;
+
+
+// Returns the tickcounter based on QueryPerformanceCounter or timeGetTime.
 int64_t OS::Ticks() {
+  static LARGE_INTEGER tick;
+  if (frequency != 0 && QueryPerformanceCounter(&tick)) {
+    return static_cast<int64_t>(tick.QuadPart * 1e6 / frequency->QuadPart);
+  }
   return timeGetTime() * 1000;  // Convert to microseconds.
 }
 
@@ -2087,12 +2095,15 @@ void OS::SetUp() {
   // call this setup code within the same millisecond.
   uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
   srand(static_cast<unsigned int>(seed));
+  // Get the number of ticks per second that is used in OS::Ticks()
+  QueryPerformanceFrequency(&frequency);
   limit_mutex = CreateMutex();
   SamplerThread::SetUp();
 }
 
 
 void OS::TearDown() {
+  frequency = 0;
   SamplerThread::TearDown();
   delete limit_mutex;
 }