OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 // Windows Timer Primer | 6 // Windows Timer Primer |
7 // | 7 // |
8 // A good article: http://www.ddj.com/windows/184416651 | 8 // A good article: http://www.ddj.com/windows/184416651 |
9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258 | 9 // A good mozilla bug: http://bugzilla.mozilla.org/show_bug.cgi?id=363258 |
10 // | 10 // |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 bool IsUsingHighResClock() { | 325 bool IsUsingHighResClock() { |
326 return ticks_per_microsecond_ != 0.0; | 326 return ticks_per_microsecond_ != 0.0; |
327 } | 327 } |
328 | 328 |
329 void DisableHighResClock() { | 329 void DisableHighResClock() { |
330 ticks_per_microsecond_ = 0.0; | 330 ticks_per_microsecond_ = 0.0; |
331 } | 331 } |
332 | 332 |
333 TimeDelta Now() { | 333 TimeDelta Now() { |
334 // Our maximum tolerance for QPC drifting. | 334 // Our maximum tolerance for QPC drifting. |
335 const int kMaxTimeDrift = 50 * Time::kMicrosecondsPerMillisecond; | 335 const int kMaxTimeDriftMicroseconds = 60150; |
336 | 336 |
337 if (IsUsingHighResClock()) { | 337 if (IsUsingHighResClock()) { |
338 int64 now = UnreliableNow(); | 338 int64 now = UnreliableNow(); |
339 | 339 |
340 // Verify that QPC does not seem to drift. | 340 // Verify that QPC does not seem to drift. |
341 DCHECK_LT(now - ReliableNow() - skew_, kMaxTimeDrift); | 341 DCHECK_LT(abs((now - ReliableNow()) - skew_), kMaxTimeDriftMicroseconds); |
342 | 342 |
343 return TimeDelta::FromMicroseconds(now); | 343 return TimeDelta::FromMicroseconds(now); |
344 } | 344 } |
345 | 345 |
346 // Just fallback to the slower clock. | 346 // Just fallback to the slower clock. |
347 return RolloverProtectedNow(); | 347 return RolloverProtectedNow(); |
348 } | 348 } |
349 | 349 |
350 private: | 350 private: |
351 // Synchronize the QPC clock with GetSystemTimeAsFileTime. | 351 // Synchronize the QPC clock with GetSystemTimeAsFileTime. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 391 |
392 // static | 392 // static |
393 TimeTicks TimeTicks::Now() { | 393 TimeTicks TimeTicks::Now() { |
394 return TimeTicks() + RolloverProtectedNow(); | 394 return TimeTicks() + RolloverProtectedNow(); |
395 } | 395 } |
396 | 396 |
397 // static | 397 // static |
398 TimeTicks TimeTicks::HighResNow() { | 398 TimeTicks TimeTicks::HighResNow() { |
399 return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now(); | 399 return TimeTicks() + Singleton<HighResNowSingleton>::get()->Now(); |
400 } | 400 } |
OLD | NEW |