From 6b1753827c4f458b55eae64bfa0f8a699ebcee4c Mon Sep 17 00:00:00 2001 From: "markus@chromium.org" Date: Tue, 13 Oct 2009 06:47:47 +0000 Subject: This is a second attempt at submitting this changelist. The original one was http://codereview.chromium.org/196053 It turns out, since none of our tests abstract time correctly, unittests are very sensitive to subtle changes in timing. This made some of the valgrind tests on Linux fail, and unfortunately, neither my desktop nor the trybots could reproduce the problem reliably. As far as I can tell, all the (design) bugs are in the unittests. The browser is actually fine. Tweaked the code a little more. Will resubmit and carefully monitor the buildbots. Original change description follows: When converting between units of time or data types of different precision, we have to be careful to consistently round in the same direction. Timeout checks usually check if Now() is less or equal to a deadline in order to determine if a timeout has occurred. This correctly handles the case where actual sleep times are equal or longer than requested sleep times. But if we round down when setting the sleep delay, this can result in unnecessary and expensive looping. Make sure, we always round up when converting to a format with less precision. BUG=none TEST=none Review URL: http://codereview.chromium.org/257044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28801 0039d316-1c4b-4281-b951-d872f2087c98 --- base/time.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'base/time.h') diff --git a/base/time.h b/base/time.h index 6a181af..8cd752a 100644 --- a/base/time.h +++ b/base/time.h @@ -64,6 +64,9 @@ class TimeDelta { // Returns the time delta in some unit. The F versions return a floating // point value, the "regular" versions return a rounded-down value. + // + // InMillisecondsRoundedUp() instead returns an integer that is rounded up + // to the next full millisecond. int InDays() const; int InHours() const; int InMinutes() const; @@ -71,6 +74,7 @@ class TimeDelta { int64 InSeconds() const; double InMillisecondsF() const; int64 InMilliseconds() const; + int64 InMillisecondsRoundedUp() const; int64 InMicroseconds() const; TimeDelta& operator=(TimeDelta other) { -- cgit v1.1