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

Unified Diff: base/time/time_win.cc

Issue 541203002: fix for high resolution timer on windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits fixes Created 6 years, 3 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/message_loop/message_loop_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time_win.cc
diff --git a/base/time/time_win.cc b/base/time/time_win.cc
index 492b54a93f126717ad0b2c339e75322bdeeb1532..2586cb318a4a149e2ea88e387291bae63881e8fc 100644
--- a/base/time/time_win.cc
+++ b/base/time/time_win.cc
@@ -92,7 +92,7 @@ const int kMinTimerIntervalLowResMs = 4;
// Track if kMinTimerIntervalHighResMs or kMinTimerIntervalLowResMs is active.
bool g_high_res_timer_enabled = false;
// How many times the high resolution timer has been called.
-int g_high_res_timer_count = 0;
+uint32_t g_high_res_timer_count = 0;
// The lock to control access to the above two variables.
base::LazyInstance<base::Lock>::Leaky g_high_res_lock =
LAZY_INSTANCE_INITIALIZER;
@@ -197,17 +197,20 @@ bool Time::ActivateHighResolutionTimer(bool activating) {
// We only do work on the transition from zero to one or one to zero so we
// can easily undo the effect (if necessary) when EnableHighResolutionTimer is
// called.
+ const uint32_t max = std::numeric_limits<uint32_t>::max();
+
base::AutoLock lock(g_high_res_lock.Get());
UINT period = g_high_res_timer_enabled ? kMinTimerIntervalHighResMs
: kMinTimerIntervalLowResMs;
- int high_res_count =
- activating ? ++g_high_res_timer_count : --g_high_res_timer_count;
-
if (activating) {
- if (high_res_count == 1)
+ DCHECK(g_high_res_timer_count != max);
+ ++g_high_res_timer_count;
+ if (g_high_res_timer_count == 1)
timeBeginPeriod(period);
} else {
- if (high_res_count == 0)
+ DCHECK(g_high_res_timer_count != 0);
+ --g_high_res_timer_count;
+ if (g_high_res_timer_count == 0)
timeEndPeriod(period);
}
return (period == kMinTimerIntervalHighResMs);
« no previous file with comments | « base/message_loop/message_loop_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698