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

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: 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..3946bb17651b642c93bd3fc5b3a9ff6adb17a674 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;
+unsigned int g_high_res_timer_count = 0;
jamesr 2014/09/04 22:56:03 uint32_t 'unsigned int' is redundant and we don't
// The lock to control access to the above two variables.
base::LazyInstance<base::Lock>::Leaky g_high_res_lock =
LAZY_INSTANCE_INITIALIZER;
@@ -197,10 +197,17 @@ 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 unsigned int max = std::numeric_limits<unsigned int>::max();
jamesr 2014/09/04 22:56:03 uint32_t
+
base::AutoLock lock(g_high_res_lock.Get());
UINT period = g_high_res_timer_enabled ? kMinTimerIntervalHighResMs
: kMinTimerIntervalLowResMs;
- int high_res_count =
+
+ // Check for overflow or underflow.
+ DCHECK((g_high_res_timer_count != 0) || activating);
+ DCHECK((g_high_res_timer_count != max) || !activating);
+
+ unsigned int high_res_count =
activating ? ++g_high_res_timer_count : --g_high_res_timer_count;
if (activating) {
« 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