diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-20 01:13:40 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-20 01:13:40 +0000 |
commit | 3816f46725f7b8e42e352a063efd5206a46dbe9a (patch) | |
tree | d64edfcf741dcd927ce404f66dab723e8a0914c8 /base/message_pump_default.cc | |
parent | bda05798c0609582075a3b872c37ad56021920c4 (diff) | |
download | chromium_src-3816f46725f7b8e42e352a063efd5206a46dbe9a.zip chromium_src-3816f46725f7b8e42e352a063efd5206a46dbe9a.tar.gz chromium_src-3816f46725f7b8e42e352a063efd5206a46dbe9a.tar.bz2 |
rollback r1075 to see if it helps resolve test failures
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_default.cc')
-rw-r--r-- | base/message_pump_default.cc | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/base/message_pump_default.cc b/base/message_pump_default.cc index a45f480..916d035 100644 --- a/base/message_pump_default.cc +++ b/base/message_pump_default.cc @@ -51,13 +51,9 @@ 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. - did_work = delegate->DoDelayedWork(&delayed_work_time_); + TimeDelta delay; + did_work = delegate->DoDelayedWork(&delay); if (!keep_running_) break; if (did_work) @@ -68,18 +64,13 @@ 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 (delayed_work_time_.is_null()) { + if (delay < TimeDelta::FromMilliseconds(0)) { event_.Wait(); } else { - 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(); - } + event_.TimedWait(delay); } // Since event_ is auto-reset, we don't need to do anything special here // other than service each delegate method. @@ -98,11 +89,12 @@ void MessagePumpDefault::ScheduleWork() { event_.Signal(); } -void MessagePumpDefault::ScheduleDelayedWork(const Time& delayed_work_time) { +void MessagePumpDefault::ScheduleDelayedWork(const TimeDelta& delay) { // 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, so we only need to update our - // record of how long to sleep when we do sleep. - delayed_work_time_ = delayed_work_time; + // 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(); } } // namespace base |