summaryrefslogtreecommitdiffstats
path: root/base/message_pump_default.cc
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-20 00:25:57 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-20 00:25:57 +0000
commit1a2bfdd793e88a64f78b38d23303550cfd0703eb (patch)
tree90ef0670a00f72c3e0cc2499866d5627511a4867 /base/message_pump_default.cc
parent7759c9a7b587662988fa1357c17c273ee64fb3bd (diff)
downloadchromium_src-1a2bfdd793e88a64f78b38d23303550cfd0703eb.zip
chromium_src-1a2bfdd793e88a64f78b38d23303550cfd0703eb.tar.gz
chromium_src-1a2bfdd793e88a64f78b38d23303550cfd0703eb.tar.bz2
Eliminate TimerManager::GetCurrentDelay in favor of always referring to the fire time of the next timer. I changed the MessagePump API to refer to a delayed_work_time instead of a delay.
I moved the ceil-based rounding code into the Window's implementations of WaitableEvent and MessagePump. R=jar git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1075 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_default.cc')
-rw-r--r--base/message_pump_default.cc30
1 files changed, 19 insertions, 11 deletions
diff --git a/base/message_pump_default.cc b/base/message_pump_default.cc
index 916d035..a45f480 100644
--- a/base/message_pump_default.cc
+++ b/base/message_pump_default.cc
@@ -51,9 +51,13 @@ void MessagePumpDefault::Run(Delegate* delegate) {
// TODO(darin): Delayed work will be starved if DoWork continues to return
// true. We should devise a better strategy.
+ //
+ // It is tempting to call DoWork followed by DoDelayedWork before checking
+ // did_work, but we need to make sure that any tasks that were dispatched
+ // prior to a timer actually run before the timer. Getting that right may
+ // require some additional changes.
- TimeDelta delay;
- did_work = delegate->DoDelayedWork(&delay);
+ did_work = delegate->DoDelayedWork(&delayed_work_time_);
if (!keep_running_)
break;
if (did_work)
@@ -64,13 +68,18 @@ void MessagePumpDefault::Run(Delegate* delegate) {
break;
if (did_work)
continue;
- // When DoIdleWork does not work, we also assume that it ran very quickly
- // such that |delay| still properly indicates how long we are to sleep.
- if (delay < TimeDelta::FromMilliseconds(0)) {
+ if (delayed_work_time_.is_null()) {
event_.Wait();
} else {
- event_.TimedWait(delay);
+ TimeDelta delay = delayed_work_time_ - Time::Now();
+ if (delay > TimeDelta()) {
+ event_.TimedWait(delay);
+ } else {
+ // It looks like delayed_work_time_ indicates a time in the past, so we
+ // need to call DoDelayedWork now.
+ delayed_work_time_ = Time();
+ }
}
// Since event_ is auto-reset, we don't need to do anything special here
// other than service each delegate method.
@@ -89,12 +98,11 @@ void MessagePumpDefault::ScheduleWork() {
event_.Signal();
}
-void MessagePumpDefault::ScheduleDelayedWork(const TimeDelta& delay) {
+void MessagePumpDefault::ScheduleDelayedWork(const Time& delayed_work_time) {
// We know that we can't be blocked on Wait right now since this method can
- // only be called on the same thread as Run, but to ensure that when we do
- // sleep, we sleep for the right time, we signal the event to cause the Run
- // loop to do one more iteration.
- event_.Signal();
+ // only be called on the same thread as Run, so we only need to update our
+ // record of how long to sleep when we do sleep.
+ delayed_work_time_ = delayed_work_time;
}
} // namespace base