diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 21:34:03 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 21:34:03 +0000 |
commit | 2a006f2a0c71c671157686f66fa80168f6ca6624 (patch) | |
tree | 8858129d90c80d90965c7672ecf0a3b1504e934d | |
parent | 121a9c519724c978ea179991bddcc5b5556e36eb (diff) | |
download | chromium_src-2a006f2a0c71c671157686f66fa80168f6ca6624.zip chromium_src-2a006f2a0c71c671157686f66fa80168f6ca6624.tar.gz chromium_src-2a006f2a0c71c671157686f66fa80168f6ca6624.tar.bz2 |
Drop the wakeup pipe completely and use the builtin glib wakeup.
Review URL: http://codereview.chromium.org/10848
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5296 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/message_pump_glib.cc | 32 | ||||
-rw-r--r-- | base/message_pump_glib.h | 10 |
2 files changed, 3 insertions, 39 deletions
diff --git a/base/message_pump_glib.cc b/base/message_pump_glib.cc index e4efd8b..ae6d88e 100644 --- a/base/message_pump_glib.cc +++ b/base/message_pump_glib.cc @@ -86,33 +86,14 @@ namespace base { MessagePumpForUI::MessagePumpForUI() : state_(NULL), - context_(g_main_context_default()), - work_source_poll_fd_(new GPollFD) { - // Create a pipe with a non-blocking read end for use by ScheduleWork to - // break us out of a poll. Create the work source and attach the file - // descriptor to it. - int pipe_fd[2]; - CHECK(0 == pipe(pipe_fd)) << "Could not create pipe!"; - write_fd_work_scheduled_ = pipe_fd[1]; - read_fd_work_scheduled_ = pipe_fd[0]; - int flags = fcntl(read_fd_work_scheduled_, F_GETFL, 0); - if (-1 == flags) - flags = 0; - CHECK(0 == fcntl(read_fd_work_scheduled_, F_SETFL, flags | O_NONBLOCK)) << - "Could not set file descriptor to non-blocking!"; - work_source_poll_fd_->fd = read_fd_work_scheduled_; - work_source_poll_fd_->events = G_IO_IN | G_IO_HUP | G_IO_ERR; - + context_(g_main_context_default()) { work_source_ = g_source_new(&WorkSourceFuncs, sizeof(WorkSource)); // This is needed to allow Run calls inside Dispatch. g_source_set_can_recurse(work_source_, TRUE); - g_source_add_poll(work_source_, work_source_poll_fd_.get()); g_source_attach(work_source_, context_); } MessagePumpForUI::~MessagePumpForUI() { - close(read_fd_work_scheduled_); - close(write_fd_work_scheduled_); g_source_destroy(work_source_); g_source_unref(work_source_); } @@ -153,10 +134,6 @@ void MessagePumpForUI::Run(Delegate* delegate) { more_work_is_plausible = false; - // Drain our wakeup pipe, this is a non-blocking read. - char tempbuf[16]; - while (read(read_fd_work_scheduled_, tempbuf, sizeof(tempbuf)) > 0) { } - if (state_->delegate->DoWork()) more_work_is_plausible = true; @@ -193,11 +170,8 @@ void MessagePumpForUI::Quit() { void MessagePumpForUI::ScheduleWork() { // This can be called on any thread, so we don't want to touch any state // variables as we would then need locks all over. This ensures that if - // we are sleeping in a poll that we will wake up, and we check the pipe - // so we know when work was scheduled. - if (write(write_fd_work_scheduled_, &kWorkScheduled, 1) != 1) { - NOTREACHED() << "Could not write to the UI message loop wakeup pipe!"; - } + // we are sleeping in a poll that we will wake up. + g_main_context_wakeup(context_); } void MessagePumpForUI::ScheduleDelayedWork(const Time& delayed_work_time) { diff --git a/base/message_pump_glib.h b/base/message_pump_glib.h index 26aec49..21a80df 100644 --- a/base/message_pump_glib.h +++ b/base/message_pump_glib.h @@ -48,19 +48,9 @@ class MessagePumpForUI : public MessagePump { // This is the time when we need to do delayed work. Time delayed_work_time_; - // We use a pipe to schedule work in a thread-safe way that doesn't interfere - // with our state. When ScheduleWork is called, we write into the pipe which - // ensures poll will not sleep, since we use the read end as an event source. - // When we find data pending on the pipe, we clear it out and know we have - // been given new work. - int write_fd_work_scheduled_; - int read_fd_work_scheduled_; - // The work source. It is shared by all calls to Run and destroyed when // the message pump is destroyed. GSource* work_source_; - // The GLib poll structure needs to be owned and freed by us. - scoped_ptr<GPollFD> work_source_poll_fd_; DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI); }; |