diff options
author | markus@chromium.org <markus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-24 23:53:51 +0000 |
---|---|---|
committer | markus@chromium.org <markus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-24 23:53:51 +0000 |
commit | 545a8b0702d8054b669438e9ad3900c1b11a5123 (patch) | |
tree | 3b8c4847c2d2143cc430436ceebcb1877474ff17 /base/time.cc | |
parent | ecb0a024ee469a8d591fb95ac4f8db9c6217f462 (diff) | |
download | chromium_src-545a8b0702d8054b669438e9ad3900c1b11a5123.zip chromium_src-545a8b0702d8054b669438e9ad3900c1b11a5123.tar.gz chromium_src-545a8b0702d8054b669438e9ad3900c1b11a5123.tar.bz2 |
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/196053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27146 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time.cc')
-rw-r--r-- | base/time.cc | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/base/time.cc b/base/time.cc index afe8c8f..2c40d21 100644 --- a/base/time.cc +++ b/base/time.cc @@ -41,6 +41,11 @@ int64 TimeDelta::InMilliseconds() const { return delta_ / Time::kMicrosecondsPerMillisecond; } +int64 TimeDelta::InMillisecondsRoundedUp() const { + return (delta_ + Time::kMicrosecondsPerMillisecond - 1) / + Time::kMicrosecondsPerMillisecond; +} + int64 TimeDelta::InMicroseconds() const { return delta_; } |