diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-29 04:58:15 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-29 04:58:15 +0000 |
commit | 57f030a503ed96f974a4edcb8c65c982ea8fd765 (patch) | |
tree | 07036d200a6f22c529fda6db035e874ef7f5f3d5 /base/time.h | |
parent | 13729e7753dfdaf4cc90f5050827a8ebc9875390 (diff) | |
download | chromium_src-57f030a503ed96f974a4edcb8c65c982ea8fd765.zip chromium_src-57f030a503ed96f974a4edcb8c65c982ea8fd765.tar.gz chromium_src-57f030a503ed96f974a4edcb8c65c982ea8fd765.tar.bz2 |
Change chrome from statically enabling high resolution timers on windows
to enabling them dynamically - only when the application really needs
them.
I am working on some test cases for this, and will add them. But wanted
to send out the concept for review.
In this implementation, I modify the message loop to detect when the
application has requested high resolution timers. Note that there are
multiple MessageLoops active in a single process. After a period of
time, we simply shut it off again. We could have set a timer or
kept a count of active timers, or any number of more complex algorithms.
But I think this algorithm is very simple and good enough. If an
application continues needing high resolution timers for more than 1s,
we'll turn the high-resolution timers back on again.
One last change - since we've implemented the clamp at 4ms, there isn't
a lot of point to our use of 1ms for timeBeginPeriod. I've modified
that to 2 (which is half of 4ms, our target minimal interval).
BUG=46531
TEST=MessageLoop.HighResolutionTimers
Review URL: http://codereview.chromium.org/2822035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51102 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time.h')
-rw-r--r-- | base/time.h | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/base/time.h b/base/time.h index 6e9a8a4..98a711d 100644 --- a/base/time.h +++ b/base/time.h @@ -254,9 +254,27 @@ class Time { static Time FromFileTime(FILETIME ft); FILETIME ToFileTime() const; - // Enable or disable Windows high resolution timer. For more details - // see comments in time_win.cc. Returns true on success. - static bool UseHighResolutionTimer(bool use); + // The minimum time of a low resolution timer. This is basically a windows + // constant of ~15.6ms. While it does vary on some older OS versions, we'll + // treat it as static across all windows versions. + static const int kMinLowResolutionThresholdMs = 16; + + // Enable or disable Windows high resolution timer. If the high resolution + // timer is not enabled, calls to ActivateHighResolutionTimer will fail. + // When disabling the high resolution timer, this function will not cause + // the high resolution timer to be deactivated, but will prevent future + // activations. + // Must be called from the main thread. + // For more details see comments in time_win.cc. + static void EnableHighResolutionTimer(bool enable); + + // Activates or deactivates the high resolution timer based on the |activate| + // flag. If the HighResolutionTimer is not Enabled (see + // EnableHighResolutionTimer), this function will return false. Otherwise + // returns true. + // All callers to activate the high resolution timer must eventually call + // this function to deactivate the high resolution timer. + static bool ActivateHighResolutionTimer(bool activate); #endif // Converts an exploded structure representing either the local time or UTC @@ -370,6 +388,13 @@ class Time { // platform-dependent epoch. static const int64 kTimeTToMicrosecondsOffset; +#if defined(OS_WIN) + // Indicates whether fast timers are usable right now. For instance, + // when using battery power, we might elect to prevent high speed timers + // which would draw more power. + static bool high_resolution_timer_enabled_; +#endif + // Time in microseconds in UTC. int64 us_; }; |