Commit f2402377 authored by Scott Graham's avatar Scott Graham Committed by Commit Bot

fuchsia: Implement basic message pump

This does not handle file descriptor watching yet, so just uses a
generic event to handle wakeups for now.

(This isn't too clever, but gets a working-enough message loop so that
test_launcher.cc can run the base_unittests tests, which should expose
many things to do.)

Bug: 706592
Change-Id: Ia0fb2b5cb6e816fc1f19b4f85f80dd3f8ff7e215
Reviewed-on: https://chromium-review.googlesource.com/518244
Commit-Queue: Scott Graham <scottmg@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#475702}
parent 80f56cf7
......@@ -21,7 +21,10 @@ bool MessagePumpFuchsia::FileDescriptorWatcher::StopWatchingFileDescriptor() {
return false;
}
MessagePumpFuchsia::MessagePumpFuchsia() {}
MessagePumpFuchsia::MessagePumpFuchsia()
: keep_running_(true),
event_(WaitableEvent::ResetPolicy::AUTOMATIC,
WaitableEvent::InitialState::NOT_SIGNALED) {}
MessagePumpFuchsia::~MessagePumpFuchsia() {}
......@@ -35,20 +38,59 @@ bool MessagePumpFuchsia::WatchFileDescriptor(int fd,
}
void MessagePumpFuchsia::Run(Delegate* delegate) {
NOTIMPLEMENTED();
DCHECK(keep_running_);
for (;;) {
bool did_work = delegate->DoWork();
if (!keep_running_)
break;
did_work |= delegate->DoDelayedWork(&delayed_work_time_);
if (!keep_running_)
break;
if (did_work)
continue;
did_work = delegate->DoIdleWork();
if (!keep_running_)
break;
if (did_work)
continue;
if (delayed_work_time_.is_null()) {
event_.Wait();
} else {
// No need to handle already expired |delayed_work_time_| in any special
// way. When |delayed_work_time_| is in the past TimeWaitUntil returns
// promptly and |delayed_work_time_| will re-initialized on a next
// DoDelayedWork call which has to be called in order to get here again.
event_.TimedWaitUntil(delayed_work_time_);
}
// TODO(fuchsia): Handle file descriptor watching here. (maybe?)
}
keep_running_ = true;
}
void MessagePumpFuchsia::Quit() {
NOTIMPLEMENTED();
keep_running_ = false;
}
void MessagePumpFuchsia::ScheduleWork() {
NOTIMPLEMENTED();
// Since this can be called on any thread, we need to ensure that our Run
// loop wakes up.
event_.Signal();
}
void MessagePumpFuchsia::ScheduleDelayedWork(
const TimeTicks& delayed_work_time) {
NOTIMPLEMENTED();
// 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;
}
} // namespace base
......@@ -8,6 +8,7 @@
#include "base/location.h"
#include "base/macros.h"
#include "base/message_loop/message_pump.h"
#include "base/synchronization/waitable_event.h"
namespace base {
......@@ -65,6 +66,16 @@ class MessagePumpFuchsia : public MessagePump {
void ScheduleWork() override;
void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
private:
// This flag is set to false when Run should return.
bool keep_running_;
// Used to sleep until there is more work to do.
WaitableEvent event_;
// The time at which we should call DoDelayedWork.
TimeTicks delayed_work_time_;
DISALLOW_COPY_AND_ASSIGN(MessagePumpFuchsia);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment