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

Unified Diff: base/time_win.cc

Issue 3848002: Fix regression where high resolution timers could be activated even under... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: nonono - fix thread safety problem, simplify! Created 10 years, 2 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
« base/time.h ('K') | « base/time.h ('k') | no next file » | 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 62903)
+++ base/time_win.cc (working copy)
@@ -99,6 +99,7 @@
const int64 Time::kTimeTToMicrosecondsOffset = GG_INT64_C(11644473600000000);
bool Time::high_resolution_timer_enabled_ = false;
+int Time::high_resolution_timer_activated_ = 0;
// static
Time Time::Now() {
@@ -162,22 +163,36 @@
}
// static
-bool Time::ActivateHighResolutionTimer(bool activate) {
- if (!high_resolution_timer_enabled_)
+bool Time::ActivateHighResolutionTimer(bool activating) {
+ if (!high_resolution_timer_enabled_ && activating)
return false;
// Using anything other than 1ms makes timers granular
// to that interval.
const int kMinTimerIntervalMs = 1;
MMRESULT result;
- if (activate)
+ if (activating) {
result = timeBeginPeriod(kMinTimerIntervalMs);
- else
+ high_resolution_timer_activated_++;
+ } else {
result = timeEndPeriod(kMinTimerIntervalMs);
+ high_resolution_timer_activated_--;
+ }
return result == TIMERR_NOERROR;
}
// static
+bool Time::IsHighResolutionTimerInUse() {
+ // Note: we should track the high_resolution_timer_activated_ value
+ // under a lock if we want it to be accurate in a system with multiple
+ // message loops. We don't do that - because we don't want to take the
+ // expense of a lock for this. We *only* track this value so that unit
+ // tests can see if the high resolution timer is on or off.
+ return high_resolution_timer_enabled_ &&
+ high_resolution_timer_activated_ > 0;
+}
+
+// static
Time Time::FromExploded(bool is_local, const Exploded& exploded) {
// Create the system struct representing our exploded time. It will either be
// in local time or UTC.
« base/time.h ('K') | « base/time.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698