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

Unified Diff: base/time_win.cc

Issue 2822035: Change chrome from statically enabling high resolution timers on windows... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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 | « base/time.h ('k') | chrome_frame/test/net/fake_external_tab.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time_win.cc
===================================================================
--- base/time_win.cc (revision 51045)
+++ base/time_win.cc (working copy)
@@ -98,6 +98,8 @@
// static
const int64 Time::kTimeTToMicrosecondsOffset = GG_INT64_C(11644473600000000);
+bool Time::high_resolution_timer_enabled_ = false;
+
// static
Time Time::Now() {
if (initial_time == 0)
@@ -148,18 +150,31 @@
}
// static
-bool Time::UseHighResolutionTimer(bool use) {
- // TODO(mbelshe): Make sure that switching the system timer resolution
- // doesn't break Timer firing order etc. An example test would be to have
- // two threads. One would have a bunch of timers, and another would turn the
- // high resolution timer on and off.
+void Time::EnableHighResolutionTimer(bool enable) {
+ // Test for single-threaded access.
+ static PlatformThreadId my_thread = PlatformThread::CurrentId();
+ DCHECK(PlatformThread::CurrentId() == my_thread);
+ if (high_resolution_timer_enabled_ == enable)
+ return;
+
+ high_resolution_timer_enabled_ = enable;
+}
+
+// static
+bool Time::ActivateHighResolutionTimer(bool activate) {
+ if (!high_resolution_timer_enabled_)
+ return false;
+
+ // Using anything other than 1ms makes timers granular
+ // to that interval.
+ const int kMinTimerIntervalMs = 1;
MMRESULT result;
- if (use)
- result = timeBeginPeriod(1);
+ if (activate)
+ result = timeBeginPeriod(kMinTimerIntervalMs);
else
- result = timeEndPeriod(1);
- return (result == TIMERR_NOERROR);
+ result = timeEndPeriod(kMinTimerIntervalMs);
+ return result == TIMERR_NOERROR;
}
// static
« no previous file with comments | « base/time.h ('k') | chrome_frame/test/net/fake_external_tab.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698