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) { |