Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: src/platform-win32.cc

Issue 10867057: Adding a high-resolution timer to platform win32. (Closed) Base URL: http://git.chromium.org/external/v8.git@master
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform-win32.cc
diff --git a/src/platform-win32.cc b/src/platform-win32.cc
index 49463be8e00fbf8ab022e71ba8af5fccaf0f2f09..de17db59b86f337a903f4316d5de74af8612ab52 100644
--- a/src/platform-win32.cc
+++ b/src/platform-win32.cc
@@ -591,9 +591,18 @@ double OS::TimeCurrentMillis() {
return t.ToJSTime();
}
-// Returns the tickcounter based on timeGetTime.
+
+static LARGE_INTEGER* frequency = NULL;
caseq 2012/08/27 09:09:58 Does this have to be dynamically allocated?
+
+
+// Returns the tickcounter based on QueryPerformanceCounter or timeGetTime.
int64_t OS::Ticks() {
- return timeGetTime() * 1000; // Convert to microseconds.
+ static LARGE_INTEGER tick;
+ if (frequency != NULL && QueryPerformanceCounter(&tick)) {
+ return static_cast<int64_t>(tick.QuadPart * 1000000.0 / frequency->QuadPart);
+ } else {
caseq 2012/08/27 09:09:58 I'd drop the parenthesis and "else".
+ return timeGetTime() * 1000; // Convert to microseconds.
+ }
}
@@ -2087,12 +2096,20 @@ 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()
+ frequency = new LARGE_INTEGER();
+ if (!QueryPerformanceFrequency(frequency)) {
+ delete frequency;
+ frequency = NULL;
+ }
limit_mutex = CreateMutex();
SamplerThread::SetUp();
}
void OS::TearDown() {
+ delete frequency;
+ frequency = NULL;
SamplerThread::TearDown();
delete limit_mutex;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698