sky@chromium.org | f881d88 | 2009-04-11 00:09:39 +0900 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
darin@google.com | 6ddeb84 | 2008-08-15 16:31:20 +0900 | [diff] [blame] | 5 | #include "base/message_loop.h" |
| 6 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
mmentovai@google.com | fa5f993 | 2008-08-22 07:26:06 +0900 | [diff] [blame] | 9 | #include "base/compiler_specific.h" |
deanm@chromium.org | cd1ce30 | 2008-09-10 19:54:06 +0900 | [diff] [blame] | 10 | #include "base/lazy_instance.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 11 | #include "base/logging.h" |
darin@google.com | 12d40bb | 2008-08-20 03:36:23 +0900 | [diff] [blame] | 12 | #include "base/message_pump_default.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 13 | #include "base/string_util.h" |
deanm@chromium.org | cd1ce30 | 2008-09-10 19:54:06 +0900 | [diff] [blame] | 14 | #include "base/thread_local.h" |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 15 | |
mark@chromium.org | 059d049 | 2008-09-24 06:08:28 +0900 | [diff] [blame] | 16 | #if defined(OS_MACOSX) |
| 17 | #include "base/message_pump_mac.h" |
| 18 | #endif |
dkegel@google.com | 9e044ae | 2008-09-19 03:46:26 +0900 | [diff] [blame] | 19 | #if defined(OS_POSIX) |
| 20 | #include "base/message_pump_libevent.h" |
kuchhal@chromium.org | e3bd2eb | 2009-05-15 01:44:26 +0900 | [diff] [blame] | 21 | #include "base/third_party/valgrind/valgrind.h" |
dkegel@google.com | 9e044ae | 2008-09-19 03:46:26 +0900 | [diff] [blame] | 22 | #endif |
sky@chromium.org | 3f8b949 | 2009-04-28 03:17:24 +0900 | [diff] [blame] | 23 | #if defined(OS_LINUX) |
dsh@google.com | 119a252 | 2008-10-04 01:52:59 +0900 | [diff] [blame] | 24 | #include "base/message_pump_glib.h" |
| 25 | #endif |
dkegel@google.com | 9e044ae | 2008-09-19 03:46:26 +0900 | [diff] [blame] | 26 | |
dsh@google.com | 0f8dd26 | 2008-10-28 05:43:33 +0900 | [diff] [blame] | 27 | using base::Time; |
| 28 | using base::TimeDelta; |
| 29 | |
deanm@chromium.org | cd1ce30 | 2008-09-10 19:54:06 +0900 | [diff] [blame] | 30 | // A lazily created thread local storage for quick access to a thread's message |
| 31 | // loop, if one exists. This should be safe and free of static constructors. |
| 32 | static base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr( |
| 33 | base::LINKER_INITIALIZED); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 34 | |
| 35 | //------------------------------------------------------------------------------ |
| 36 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 37 | // Logical events for Histogram profiling. Run with -message-loop-histogrammer |
| 38 | // to get an accounting of messages and actions taken on each thread. |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 39 | static const int kTaskRunEvent = 0x1; |
| 40 | static const int kTimerEvent = 0x2; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 41 | |
| 42 | // Provide range of message IDs for use in histogramming and debug display. |
| 43 | static const int kLeastNonZeroMessageId = 1; |
| 44 | static const int kMaxMessageId = 1099; |
| 45 | static const int kNumberOfDistinctMessagesDisplayed = 1100; |
| 46 | |
| 47 | //------------------------------------------------------------------------------ |
| 48 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 49 | #if defined(OS_WIN) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 50 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 51 | // Upon a SEH exception in this thread, it restores the original unhandled |
| 52 | // exception filter. |
| 53 | static int SEHFilter(LPTOP_LEVEL_EXCEPTION_FILTER old_filter) { |
| 54 | ::SetUnhandledExceptionFilter(old_filter); |
| 55 | return EXCEPTION_CONTINUE_SEARCH; |
| 56 | } |
| 57 | |
| 58 | // Retrieves a pointer to the current unhandled exception filter. There |
| 59 | // is no standalone getter method. |
| 60 | static LPTOP_LEVEL_EXCEPTION_FILTER GetTopSEHFilter() { |
| 61 | LPTOP_LEVEL_EXCEPTION_FILTER top_filter = NULL; |
| 62 | top_filter = ::SetUnhandledExceptionFilter(0); |
| 63 | ::SetUnhandledExceptionFilter(top_filter); |
| 64 | return top_filter; |
| 65 | } |
| 66 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 67 | #endif // defined(OS_WIN) |
| 68 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 69 | //------------------------------------------------------------------------------ |
| 70 | |
deanm@chromium.org | cd1ce30 | 2008-09-10 19:54:06 +0900 | [diff] [blame] | 71 | // static |
| 72 | MessageLoop* MessageLoop::current() { |
| 73 | // TODO(darin): sadly, we cannot enable this yet since people call us even |
| 74 | // when they have no intention of using us. |
| 75 | //DCHECK(loop) << "Ouch, did you forget to initialize me?"; |
| 76 | return lazy_tls_ptr.Pointer()->Get(); |
| 77 | } |
| 78 | |
darin@google.com | d936b5b | 2008-08-26 14:53:57 +0900 | [diff] [blame] | 79 | MessageLoop::MessageLoop(Type type) |
| 80 | : type_(type), |
darin@google.com | ee6fa72 | 2008-08-13 08:25:43 +0900 | [diff] [blame] | 81 | nestable_tasks_allowed_(true), |
darin@google.com | 12d40bb | 2008-08-20 03:36:23 +0900 | [diff] [blame] | 82 | exception_restoration_(false), |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 83 | state_(NULL), |
| 84 | next_sequence_num_(0) { |
deanm@chromium.org | cd1ce30 | 2008-09-10 19:54:06 +0900 | [diff] [blame] | 85 | DCHECK(!current()) << "should only have one message loop per thread"; |
| 86 | lazy_tls_ptr.Pointer()->Set(this); |
darin@google.com | d936b5b | 2008-08-26 14:53:57 +0900 | [diff] [blame] | 87 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 88 | #if defined(OS_WIN) |
rvargas@google.com | 670c312 | 2008-09-26 05:33:04 +0900 | [diff] [blame] | 89 | // TODO(rvargas): Get rid of the OS guards. |
darin@google.com | 0795f57 | 2008-08-30 09:22:48 +0900 | [diff] [blame] | 90 | if (type_ == TYPE_DEFAULT) { |
| 91 | pump_ = new base::MessagePumpDefault(); |
rvargas@google.com | 670c312 | 2008-09-26 05:33:04 +0900 | [diff] [blame] | 92 | } else if (type_ == TYPE_IO) { |
| 93 | pump_ = new base::MessagePumpForIO(); |
darin@google.com | 0795f57 | 2008-08-30 09:22:48 +0900 | [diff] [blame] | 94 | } else { |
rvargas@google.com | 670c312 | 2008-09-26 05:33:04 +0900 | [diff] [blame] | 95 | DCHECK(type_ == TYPE_UI); |
| 96 | pump_ = new base::MessagePumpForUI(); |
darin@google.com | 0795f57 | 2008-08-30 09:22:48 +0900 | [diff] [blame] | 97 | } |
dkegel@google.com | 9e044ae | 2008-09-19 03:46:26 +0900 | [diff] [blame] | 98 | #elif defined(OS_POSIX) |
mark@chromium.org | 059d049 | 2008-09-24 06:08:28 +0900 | [diff] [blame] | 99 | if (type_ == TYPE_UI) { |
dsh@google.com | 119a252 | 2008-10-04 01:52:59 +0900 | [diff] [blame] | 100 | #if defined(OS_MACOSX) |
mark@chromium.org | 059d049 | 2008-09-24 06:08:28 +0900 | [diff] [blame] | 101 | pump_ = base::MessagePumpMac::Create(); |
dsh@google.com | 119a252 | 2008-10-04 01:52:59 +0900 | [diff] [blame] | 102 | #elif defined(OS_LINUX) |
| 103 | pump_ = new base::MessagePumpForUI(); |
| 104 | #endif // OS_LINUX |
| 105 | } else if (type_ == TYPE_IO) { |
dkegel@google.com | 9e044ae | 2008-09-19 03:46:26 +0900 | [diff] [blame] | 106 | pump_ = new base::MessagePumpLibevent(); |
| 107 | } else { |
| 108 | pump_ = new base::MessagePumpDefault(); |
| 109 | } |
mark@chromium.org | 059d049 | 2008-09-24 06:08:28 +0900 | [diff] [blame] | 110 | #endif // OS_POSIX |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | MessageLoop::~MessageLoop() { |
| 114 | DCHECK(this == current()); |
darin@google.com | 965e534 | 2008-08-06 08:16:41 +0900 | [diff] [blame] | 115 | |
| 116 | // Let interested parties have one last shot at accessing this. |
| 117 | FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, |
| 118 | WillDestroyCurrentMessageLoop()); |
| 119 | |
darin@google.com | 0e50050 | 2008-09-09 14:55:35 +0900 | [diff] [blame] | 120 | DCHECK(!state_); |
| 121 | |
darin@chromium.org | e3af17f | 2008-09-10 09:37:07 +0900 | [diff] [blame] | 122 | // Clean up any unprocessed tasks, but take care: deleting a task could |
| 123 | // result in the addition of more tasks (e.g., via DeleteSoon). We set a |
| 124 | // limit on the number of times we will allow a deleted task to generate more |
| 125 | // tasks. Normally, we should only pass through this loop once or twice. If |
| 126 | // we end up hitting the loop limit, then it is probably due to one task that |
| 127 | // is being stubborn. Inspect the queues to see who is left. |
| 128 | bool did_work; |
| 129 | for (int i = 0; i < 100; ++i) { |
| 130 | DeletePendingTasks(); |
| 131 | ReloadWorkQueue(); |
| 132 | // If we end up with empty queues, then break out of the loop. |
| 133 | did_work = DeletePendingTasks(); |
| 134 | if (!did_work) |
| 135 | break; |
darin@google.com | 0e50050 | 2008-09-09 14:55:35 +0900 | [diff] [blame] | 136 | } |
darin@chromium.org | e3af17f | 2008-09-10 09:37:07 +0900 | [diff] [blame] | 137 | DCHECK(!did_work); |
| 138 | |
| 139 | // OK, now make it so that no one can find us. |
deanm@chromium.org | e4cc592 | 2008-09-10 20:14:56 +0900 | [diff] [blame] | 140 | lazy_tls_ptr.Pointer()->Set(NULL); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 141 | } |
| 142 | |
darin@google.com | 965e534 | 2008-08-06 08:16:41 +0900 | [diff] [blame] | 143 | void MessageLoop::AddDestructionObserver(DestructionObserver *obs) { |
| 144 | DCHECK(this == current()); |
| 145 | destruction_observers_.AddObserver(obs); |
| 146 | } |
| 147 | |
| 148 | void MessageLoop::RemoveDestructionObserver(DestructionObserver *obs) { |
| 149 | DCHECK(this == current()); |
| 150 | destruction_observers_.RemoveObserver(obs); |
| 151 | } |
| 152 | |
darin@google.com | 6ddeb84 | 2008-08-15 16:31:20 +0900 | [diff] [blame] | 153 | void MessageLoop::Run() { |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 154 | AutoRunState save_state(this); |
| 155 | RunHandler(); |
darin@google.com | 6ddeb84 | 2008-08-15 16:31:20 +0900 | [diff] [blame] | 156 | } |
| 157 | |
jar@google.com | 9239e02 | 2008-07-31 22:10:20 +0900 | [diff] [blame] | 158 | void MessageLoop::RunAllPending() { |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 159 | AutoRunState save_state(this); |
| 160 | state_->quit_received = true; // Means run until we would otherwise block. |
| 161 | RunHandler(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | // Runs the loop in two different SEH modes: |
| 165 | // enable_SEH_restoration_ = false : any unhandled exception goes to the last |
| 166 | // one that calls SetUnhandledExceptionFilter(). |
| 167 | // enable_SEH_restoration_ = true : any unhandled exception goes to the filter |
| 168 | // that was existed before the loop was run. |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 169 | void MessageLoop::RunHandler() { |
| 170 | #if defined(OS_WIN) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 171 | if (exception_restoration_) { |
| 172 | LPTOP_LEVEL_EXCEPTION_FILTER current_filter = GetTopSEHFilter(); |
| 173 | __try { |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 174 | RunInternal(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 175 | } __except(SEHFilter(current_filter)) { |
| 176 | } |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 177 | return; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 178 | } |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 179 | #endif |
| 180 | |
| 181 | RunInternal(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | //------------------------------------------------------------------------------ |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 185 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 186 | void MessageLoop::RunInternal() { |
| 187 | DCHECK(this == current()); |
| 188 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 189 | StartHistogrammer(); |
| 190 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 191 | #if defined(OS_WIN) |
| 192 | if (state_->dispatcher) { |
| 193 | pump_win()->RunWithDispatcher(this, state_->dispatcher); |
| 194 | return; |
jar@google.com | 9239e02 | 2008-07-31 22:10:20 +0900 | [diff] [blame] | 195 | } |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 196 | #endif |
jeremy@chromium.org | 2ed223c | 2008-12-09 02:36:06 +0900 | [diff] [blame] | 197 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 198 | pump_->Run(this); |
jar@google.com | fbaaf69 | 2008-07-30 16:50:53 +0900 | [diff] [blame] | 199 | } |
jar@google.com | 7ff36e6 | 2008-07-30 15:58:56 +0900 | [diff] [blame] | 200 | |
jar@google.com | b4d1bff | 2008-07-31 04:03:59 +0900 | [diff] [blame] | 201 | //------------------------------------------------------------------------------ |
| 202 | // Wrapper functions for use in above message loop framework. |
| 203 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 204 | bool MessageLoop::ProcessNextDelayedNonNestableTask() { |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 205 | if (state_->run_depth != 1) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 206 | return false; |
| 207 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 208 | if (deferred_non_nestable_work_queue_.empty()) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 209 | return false; |
jeremy@chromium.org | 2ed223c | 2008-12-09 02:36:06 +0900 | [diff] [blame] | 210 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 211 | Task* task = deferred_non_nestable_work_queue_.front().task; |
| 212 | deferred_non_nestable_work_queue_.pop(); |
jeremy@chromium.org | 2ed223c | 2008-12-09 02:36:06 +0900 | [diff] [blame] | 213 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 214 | RunTask(task); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 215 | return true; |
| 216 | } |
| 217 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 218 | //------------------------------------------------------------------------------ |
| 219 | |
| 220 | void MessageLoop::Quit() { |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 221 | DCHECK(current() == this); |
| 222 | if (state_) { |
| 223 | state_->quit_received = true; |
| 224 | } else { |
| 225 | NOTREACHED() << "Must be inside Run to call Quit"; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 226 | } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 227 | } |
| 228 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 229 | void MessageLoop::PostTask( |
| 230 | const tracked_objects::Location& from_here, Task* task) { |
| 231 | PostTask_Helper(from_here, task, 0, true); |
| 232 | } |
| 233 | |
| 234 | void MessageLoop::PostDelayedTask( |
phajdan.jr@chromium.org | c3c9225 | 2009-06-18 02:23:51 +0900 | [diff] [blame] | 235 | const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 236 | PostTask_Helper(from_here, task, delay_ms, true); |
| 237 | } |
| 238 | |
| 239 | void MessageLoop::PostNonNestableTask( |
| 240 | const tracked_objects::Location& from_here, Task* task) { |
| 241 | PostTask_Helper(from_here, task, 0, false); |
| 242 | } |
| 243 | |
| 244 | void MessageLoop::PostNonNestableDelayedTask( |
phajdan.jr@chromium.org | c3c9225 | 2009-06-18 02:23:51 +0900 | [diff] [blame] | 245 | const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 246 | PostTask_Helper(from_here, task, delay_ms, false); |
| 247 | } |
| 248 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 249 | // Possibly called on a background thread! |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 250 | void MessageLoop::PostTask_Helper( |
phajdan.jr@chromium.org | c3c9225 | 2009-06-18 02:23:51 +0900 | [diff] [blame] | 251 | const tracked_objects::Location& from_here, Task* task, int64 delay_ms, |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 252 | bool nestable) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 253 | task->SetBirthPlace(from_here); |
darin@google.com | 0795f57 | 2008-08-30 09:22:48 +0900 | [diff] [blame] | 254 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 255 | PendingTask pending_task(task, nestable); |
darin@google.com | 0795f57 | 2008-08-30 09:22:48 +0900 | [diff] [blame] | 256 | |
| 257 | if (delay_ms > 0) { |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 258 | pending_task.delayed_run_time = |
darin@google.com | 0795f57 | 2008-08-30 09:22:48 +0900 | [diff] [blame] | 259 | Time::Now() + TimeDelta::FromMilliseconds(delay_ms); |
| 260 | } else { |
| 261 | DCHECK(delay_ms == 0) << "delay should not be negative"; |
| 262 | } |
| 263 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 264 | // Warning: Don't try to short-circuit, and handle this thread's tasks more |
| 265 | // directly, as it could starve handling of foreign threads. Put every task |
| 266 | // into this queue. |
| 267 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 268 | scoped_refptr<base::MessagePump> pump; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 269 | { |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 270 | AutoLock locked(incoming_queue_lock_); |
| 271 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 272 | bool was_empty = incoming_queue_.empty(); |
| 273 | incoming_queue_.push(pending_task); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 274 | if (!was_empty) |
| 275 | return; // Someone else should have started the sub-pump. |
| 276 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 277 | pump = pump_; |
darin@google.com | 6ddeb84 | 2008-08-15 16:31:20 +0900 | [diff] [blame] | 278 | } |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 279 | // Since the incoming_queue_ may contain a task that destroys this message |
| 280 | // loop, we cannot exit incoming_queue_lock_ until we are done with |this|. |
| 281 | // We use a stack-based reference to the message pump so that we can call |
| 282 | // ScheduleWork outside of incoming_queue_lock_. |
darin@google.com | 6ddeb84 | 2008-08-15 16:31:20 +0900 | [diff] [blame] | 283 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 284 | pump->ScheduleWork(); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | void MessageLoop::SetNestableTasksAllowed(bool allowed) { |
mpcomplete@google.com | 989d5f8 | 2008-08-09 09:14:09 +0900 | [diff] [blame] | 288 | if (nestable_tasks_allowed_ != allowed) { |
| 289 | nestable_tasks_allowed_ = allowed; |
| 290 | if (!nestable_tasks_allowed_) |
| 291 | return; |
| 292 | // Start the native pump if we are not already pumping. |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 293 | pump_->ScheduleWork(); |
mpcomplete@google.com | 989d5f8 | 2008-08-09 09:14:09 +0900 | [diff] [blame] | 294 | } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | bool MessageLoop::NestableTasksAllowed() const { |
| 298 | return nestable_tasks_allowed_; |
| 299 | } |
| 300 | |
jcampan@chromium.org | eac5717 | 2009-07-02 04:53:59 +0900 | [diff] [blame^] | 301 | bool MessageLoop::IsNested() { |
| 302 | return state_->run_depth > 1; |
| 303 | } |
| 304 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 305 | //------------------------------------------------------------------------------ |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 306 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 307 | void MessageLoop::RunTask(Task* task) { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 308 | DCHECK(nestable_tasks_allowed_); |
| 309 | // Execute the task and assume the worst: It is probably not reentrant. |
| 310 | nestable_tasks_allowed_ = false; |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 311 | |
| 312 | HistogramEvent(kTaskRunEvent); |
| 313 | task->Run(); |
| 314 | delete task; |
| 315 | |
| 316 | nestable_tasks_allowed_ = true; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 317 | } |
| 318 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 319 | bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { |
| 320 | if (pending_task.nestable || state_->run_depth == 1) { |
| 321 | RunTask(pending_task.task); |
| 322 | // Show that we ran a task (Note: a new one might arrive as a |
| 323 | // consequence!). |
| 324 | return true; |
| 325 | } |
| 326 | |
| 327 | // We couldn't run the task now because we're in a nested message loop |
| 328 | // and the task isn't nestable. |
| 329 | deferred_non_nestable_work_queue_.push(pending_task); |
| 330 | return false; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 331 | } |
| 332 | |
darin@chromium.org | e3af17f | 2008-09-10 09:37:07 +0900 | [diff] [blame] | 333 | void MessageLoop::AddToDelayedWorkQueue(const PendingTask& pending_task) { |
| 334 | // Move to the delayed work queue. Initialize the sequence number |
| 335 | // before inserting into the delayed_work_queue_. The sequence number |
| 336 | // is used to faciliate FIFO sorting when two tasks have the same |
| 337 | // delayed_run_time value. |
| 338 | PendingTask new_pending_task(pending_task); |
| 339 | new_pending_task.sequence_num = next_sequence_num_++; |
| 340 | delayed_work_queue_.push(new_pending_task); |
| 341 | } |
| 342 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 343 | void MessageLoop::ReloadWorkQueue() { |
| 344 | // We can improve performance of our loading tasks from incoming_queue_ to |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 345 | // work_queue_ by waiting until the last minute (work_queue_ is empty) to |
| 346 | // load. That reduces the number of locks-per-task significantly when our |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 347 | // queues get large. |
| 348 | if (!work_queue_.empty()) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 349 | return; // Wait till we *really* need to lock and load. |
| 350 | |
| 351 | // Acquire all we can from the inter-thread queue with one lock acquisition. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 352 | { |
| 353 | AutoLock lock(incoming_queue_lock_); |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 354 | if (incoming_queue_.empty()) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 355 | return; |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 356 | std::swap(incoming_queue_, work_queue_); |
| 357 | DCHECK(incoming_queue_.empty()); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 358 | } |
| 359 | } |
| 360 | |
darin@chromium.org | e3af17f | 2008-09-10 09:37:07 +0900 | [diff] [blame] | 361 | bool MessageLoop::DeletePendingTasks() { |
| 362 | bool did_work = !work_queue_.empty(); |
| 363 | while (!work_queue_.empty()) { |
| 364 | PendingTask pending_task = work_queue_.front(); |
| 365 | work_queue_.pop(); |
| 366 | if (!pending_task.delayed_run_time.is_null()) { |
| 367 | // We want to delete delayed tasks in the same order in which they would |
| 368 | // normally be deleted in case of any funny dependencies between delayed |
| 369 | // tasks. |
| 370 | AddToDelayedWorkQueue(pending_task); |
| 371 | } else { |
| 372 | // TODO(darin): Delete all tasks once it is safe to do so. |
kuchhal@chromium.org | e3bd2eb | 2009-05-15 01:44:26 +0900 | [diff] [blame] | 373 | // Until it is totally safe, just do it when running Purify or |
| 374 | // Valgrind. |
| 375 | #if defined(OS_WIN) |
jar@chromium.org | 47fb285 | 2009-03-12 04:46:41 +0900 | [diff] [blame] | 376 | #ifdef PURIFY |
jar@chromium.org | 6377235 | 2009-03-12 05:06:02 +0900 | [diff] [blame] | 377 | delete pending_task.task; |
jar@chromium.org | 47fb285 | 2009-03-12 04:46:41 +0900 | [diff] [blame] | 378 | #endif // PURIFY |
kuchhal@chromium.org | e3bd2eb | 2009-05-15 01:44:26 +0900 | [diff] [blame] | 379 | #elif defined(OS_POSIX) |
| 380 | if (RUNNING_ON_VALGRIND) |
| 381 | delete pending_task.task; |
| 382 | #endif // defined(OS_POSIX) |
darin@chromium.org | e3af17f | 2008-09-10 09:37:07 +0900 | [diff] [blame] | 383 | } |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 384 | } |
darin@chromium.org | e3af17f | 2008-09-10 09:37:07 +0900 | [diff] [blame] | 385 | did_work |= !deferred_non_nestable_work_queue_.empty(); |
| 386 | while (!deferred_non_nestable_work_queue_.empty()) { |
jar@chromium.org | 47fb285 | 2009-03-12 04:46:41 +0900 | [diff] [blame] | 387 | // TODO(darin): Delete all tasks once it is safe to do so. |
| 388 | // Until it is totaly safe, just delete them to keep purify happy. |
| 389 | #ifdef PURIFY |
jar@chromium.org | 2fa6b4b | 2009-03-12 04:53:50 +0900 | [diff] [blame] | 390 | Task* task = deferred_non_nestable_work_queue_.front().task; |
| 391 | #endif |
| 392 | deferred_non_nestable_work_queue_.pop(); |
| 393 | #ifdef PURIFY |
jar@chromium.org | 47fb285 | 2009-03-12 04:46:41 +0900 | [diff] [blame] | 394 | delete task; |
| 395 | #endif |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 396 | } |
darin@chromium.org | e3af17f | 2008-09-10 09:37:07 +0900 | [diff] [blame] | 397 | did_work |= !delayed_work_queue_.empty(); |
| 398 | while (!delayed_work_queue_.empty()) { |
| 399 | Task* task = delayed_work_queue_.top().task; |
| 400 | delayed_work_queue_.pop(); |
| 401 | delete task; |
| 402 | } |
| 403 | return did_work; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 404 | } |
| 405 | |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 406 | bool MessageLoop::DoWork() { |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 407 | if (!nestable_tasks_allowed_) { |
| 408 | // Task can't be executed right now. |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | for (;;) { |
| 413 | ReloadWorkQueue(); |
| 414 | if (work_queue_.empty()) |
| 415 | break; |
| 416 | |
| 417 | // Execute oldest task. |
| 418 | do { |
| 419 | PendingTask pending_task = work_queue_.front(); |
| 420 | work_queue_.pop(); |
| 421 | if (!pending_task.delayed_run_time.is_null()) { |
darin@chromium.org | e3af17f | 2008-09-10 09:37:07 +0900 | [diff] [blame] | 422 | AddToDelayedWorkQueue(pending_task); |
darin@chromium.org | b2d3345 | 2008-09-24 04:19:20 +0900 | [diff] [blame] | 423 | // If we changed the topmost task, then it is time to re-schedule. |
| 424 | if (delayed_work_queue_.top().task == pending_task.task) |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 425 | pump_->ScheduleDelayedWork(pending_task.delayed_run_time); |
| 426 | } else { |
| 427 | if (DeferOrRunPendingTask(pending_task)) |
| 428 | return true; |
| 429 | } |
| 430 | } while (!work_queue_.empty()); |
| 431 | } |
| 432 | |
| 433 | // Nothing happened. |
| 434 | return false; |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 435 | } |
| 436 | |
darin@google.com | 6393bed | 2008-08-20 15:30:58 +0900 | [diff] [blame] | 437 | bool MessageLoop::DoDelayedWork(Time* next_delayed_work_time) { |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 438 | if (!nestable_tasks_allowed_ || delayed_work_queue_.empty()) { |
| 439 | *next_delayed_work_time = Time(); |
| 440 | return false; |
| 441 | } |
jeremy@chromium.org | 2ed223c | 2008-12-09 02:36:06 +0900 | [diff] [blame] | 442 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 443 | if (delayed_work_queue_.top().delayed_run_time > Time::Now()) { |
| 444 | *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time; |
| 445 | return false; |
| 446 | } |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 447 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 448 | PendingTask pending_task = delayed_work_queue_.top(); |
| 449 | delayed_work_queue_.pop(); |
jeremy@chromium.org | 2ed223c | 2008-12-09 02:36:06 +0900 | [diff] [blame] | 450 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 451 | if (!delayed_work_queue_.empty()) |
| 452 | *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time; |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 453 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 454 | return DeferOrRunPendingTask(pending_task); |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | bool MessageLoop::DoIdleWork() { |
| 458 | if (ProcessNextDelayedNonNestableTask()) |
| 459 | return true; |
| 460 | |
| 461 | if (state_->quit_received) |
| 462 | pump_->Quit(); |
| 463 | |
| 464 | return false; |
| 465 | } |
| 466 | |
| 467 | //------------------------------------------------------------------------------ |
| 468 | // MessageLoop::AutoRunState |
| 469 | |
| 470 | MessageLoop::AutoRunState::AutoRunState(MessageLoop* loop) : loop_(loop) { |
| 471 | // Make the loop reference us. |
| 472 | previous_state_ = loop_->state_; |
| 473 | if (previous_state_) { |
| 474 | run_depth = previous_state_->run_depth + 1; |
darin@google.com | 6ddeb84 | 2008-08-15 16:31:20 +0900 | [diff] [blame] | 475 | } else { |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 476 | run_depth = 1; |
darin@google.com | 6ddeb84 | 2008-08-15 16:31:20 +0900 | [diff] [blame] | 477 | } |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 478 | loop_->state_ = this; |
| 479 | |
| 480 | // Initialize the other fields: |
| 481 | quit_received = false; |
| 482 | #if defined(OS_WIN) |
| 483 | dispatcher = NULL; |
| 484 | #endif |
| 485 | } |
| 486 | |
| 487 | MessageLoop::AutoRunState::~AutoRunState() { |
| 488 | loop_->state_ = previous_state_; |
darin@google.com | ee6fa72 | 2008-08-13 08:25:43 +0900 | [diff] [blame] | 489 | } |
| 490 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 491 | //------------------------------------------------------------------------------ |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 492 | // MessageLoop::PendingTask |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 493 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 494 | bool MessageLoop::PendingTask::operator<(const PendingTask& other) const { |
| 495 | // Since the top of a priority queue is defined as the "greatest" element, we |
| 496 | // need to invert the comparison here. We want the smaller time to be at the |
| 497 | // top of the heap. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 498 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 499 | if (delayed_run_time < other.delayed_run_time) |
| 500 | return false; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 501 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 502 | if (delayed_run_time > other.delayed_run_time) |
| 503 | return true; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 504 | |
darin@google.com | be165ae | 2008-09-07 17:08:29 +0900 | [diff] [blame] | 505 | // If the times happen to match, then we use the sequence number to decide. |
| 506 | // Compare the difference to support integer roll-over. |
| 507 | return (sequence_num - other.sequence_num) > 0; |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | //------------------------------------------------------------------------------ |
| 511 | // Method and data for histogramming events and actions taken by each instance |
| 512 | // on each thread. |
| 513 | |
| 514 | // static |
| 515 | bool MessageLoop::enable_histogrammer_ = false; |
| 516 | |
| 517 | // static |
| 518 | void MessageLoop::EnableHistogrammer(bool enable) { |
| 519 | enable_histogrammer_ = enable; |
| 520 | } |
| 521 | |
| 522 | void MessageLoop::StartHistogrammer() { |
| 523 | if (enable_histogrammer_ && !message_histogram_.get() |
| 524 | && StatisticsRecorder::WasStarted()) { |
darin@google.com | 981f355 | 2008-08-16 12:09:05 +0900 | [diff] [blame] | 525 | DCHECK(!thread_name_.empty()); |
dsh@google.com | 6e7eb9f | 2009-02-25 04:08:23 +0900 | [diff] [blame] | 526 | message_histogram_.reset( |
| 527 | new LinearHistogram(("MsgLoop:" + thread_name_).c_str(), |
| 528 | kLeastNonZeroMessageId, |
| 529 | kMaxMessageId, |
| 530 | kNumberOfDistinctMessagesDisplayed)); |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 531 | message_histogram_->SetFlags(message_histogram_->kHexRangePrintingFlag); |
| 532 | message_histogram_->SetRangeDescriptions(event_descriptions_); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | void MessageLoop::HistogramEvent(int event) { |
| 537 | if (message_histogram_.get()) |
| 538 | message_histogram_->Add(event); |
| 539 | } |
| 540 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 541 | // Provide a macro that takes an expression (such as a constant, or macro |
| 542 | // constant) and creates a pair to initalize an array of pairs. In this case, |
| 543 | // our pair consists of the expressions value, and the "stringized" version |
| 544 | // of the expression (i.e., the exrpression put in quotes). For example, if |
| 545 | // we have: |
| 546 | // #define FOO 2 |
| 547 | // #define BAR 5 |
| 548 | // then the following: |
| 549 | // VALUE_TO_NUMBER_AND_NAME(FOO + BAR) |
| 550 | // will expand to: |
| 551 | // {7, "FOO + BAR"} |
| 552 | // We use the resulting array as an argument to our histogram, which reads the |
| 553 | // number as a bucket identifier, and proceeds to use the corresponding name |
| 554 | // in the pair (i.e., the quoted string) when printing out a histogram. |
| 555 | #define VALUE_TO_NUMBER_AND_NAME(name) {name, #name}, |
| 556 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 557 | // static |
| 558 | const LinearHistogram::DescriptionPair MessageLoop::event_descriptions_[] = { |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 559 | // Provide some pretty print capability in our histogram for our internal |
| 560 | // messages. |
| 561 | |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 562 | // A few events we handle (kindred to messages), and used to profile actions. |
| 563 | VALUE_TO_NUMBER_AND_NAME(kTaskRunEvent) |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 564 | VALUE_TO_NUMBER_AND_NAME(kTimerEvent) |
| 565 | |
| 566 | {-1, NULL} // The list must be null terminated, per API to histogram. |
| 567 | }; |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame] | 568 | |
darin@google.com | d936b5b | 2008-08-26 14:53:57 +0900 | [diff] [blame] | 569 | //------------------------------------------------------------------------------ |
| 570 | // MessageLoopForUI |
| 571 | |
sky@chromium.org | ff7ef5a | 2009-05-19 06:12:34 +0900 | [diff] [blame] | 572 | #if defined(OS_LINUX) || defined(OS_WIN) |
| 573 | |
| 574 | void MessageLoopForUI::AddObserver(Observer* observer) { |
| 575 | pump_ui()->AddObserver(observer); |
| 576 | } |
| 577 | |
| 578 | void MessageLoopForUI::RemoveObserver(Observer* observer) { |
| 579 | pump_ui()->RemoveObserver(observer); |
| 580 | } |
| 581 | |
| 582 | #endif |
| 583 | |
darin@google.com | d936b5b | 2008-08-26 14:53:57 +0900 | [diff] [blame] | 584 | #if defined(OS_WIN) |
| 585 | |
| 586 | void MessageLoopForUI::Run(Dispatcher* dispatcher) { |
| 587 | AutoRunState save_state(this); |
| 588 | state_->dispatcher = dispatcher; |
| 589 | RunHandler(); |
| 590 | } |
| 591 | |
darin@google.com | d936b5b | 2008-08-26 14:53:57 +0900 | [diff] [blame] | 592 | void MessageLoopForUI::WillProcessMessage(const MSG& message) { |
| 593 | pump_win()->WillProcessMessage(message); |
| 594 | } |
| 595 | void MessageLoopForUI::DidProcessMessage(const MSG& message) { |
| 596 | pump_win()->DidProcessMessage(message); |
| 597 | } |
| 598 | void MessageLoopForUI::PumpOutPendingPaintMessages() { |
rvargas@google.com | 7388754 | 2008-11-08 06:52:15 +0900 | [diff] [blame] | 599 | pump_ui()->PumpOutPendingPaintMessages(); |
darin@google.com | d936b5b | 2008-08-26 14:53:57 +0900 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | #endif // defined(OS_WIN) |
| 603 | |
| 604 | //------------------------------------------------------------------------------ |
| 605 | // MessageLoopForIO |
| 606 | |
| 607 | #if defined(OS_WIN) |
| 608 | |
rvargas@google.com | 9e49aa2 | 2008-10-10 08:58:43 +0900 | [diff] [blame] | 609 | void MessageLoopForIO::RegisterIOHandler(HANDLE file, IOHandler* handler) { |
| 610 | pump_io()->RegisterIOHandler(file, handler); |
| 611 | } |
| 612 | |
rvargas@google.com | 7388754 | 2008-11-08 06:52:15 +0900 | [diff] [blame] | 613 | bool MessageLoopForIO::WaitForIOCompletion(DWORD timeout, IOHandler* filter) { |
| 614 | return pump_io()->WaitForIOCompletion(timeout, filter); |
rvargas@google.com | 9e49aa2 | 2008-10-10 08:58:43 +0900 | [diff] [blame] | 615 | } |
| 616 | |
dkegel@google.com | 9e044ae | 2008-09-19 03:46:26 +0900 | [diff] [blame] | 617 | #elif defined(OS_POSIX) |
| 618 | |
jeremy@chromium.org | efc0db0 | 2008-12-16 07:02:17 +0900 | [diff] [blame] | 619 | bool MessageLoopForIO::WatchFileDescriptor(int fd, |
| 620 | bool persistent, |
| 621 | Mode mode, |
| 622 | FileDescriptorWatcher *controller, |
| 623 | Watcher *delegate) { |
| 624 | return pump_libevent()->WatchFileDescriptor( |
| 625 | fd, |
| 626 | persistent, |
| 627 | static_cast<base::MessagePumpLibevent::Mode>(mode), |
| 628 | controller, |
| 629 | delegate); |
dkegel@google.com | 9e044ae | 2008-09-19 03:46:26 +0900 | [diff] [blame] | 630 | } |
| 631 | |
dkegel@google.com | 9e044ae | 2008-09-19 03:46:26 +0900 | [diff] [blame] | 632 | #endif |