[email protected] | 9146221 | 2009-04-10 15:09:39 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [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 | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
[email protected] | ea15e98 | 2008-08-15 07:31:20 | [diff] [blame] | 5 | #include "base/message_loop.h" |
| 6 | |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
[email protected] | f1ea2fa | 2008-08-21 22:26:06 | [diff] [blame] | 9 | #include "base/compiler_specific.h" |
[email protected] | f886b7bf | 2008-09-10 10:54:06 | [diff] [blame] | 10 | #include "base/lazy_instance.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 11 | #include "base/logging.h" |
[email protected] | b16ef31 | 2008-08-19 18:36:23 | [diff] [blame] | 12 | #include "base/message_pump_default.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 13 | #include "base/string_util.h" |
[email protected] | f886b7bf | 2008-09-10 10:54:06 | [diff] [blame] | 14 | #include "base/thread_local.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 15 | |
[email protected] | 96c9ea1 | 2008-09-23 21:08:28 | [diff] [blame] | 16 | #if defined(OS_MACOSX) |
| 17 | #include "base/message_pump_mac.h" |
| 18 | #endif |
[email protected] | 36987e9 | 2008-09-18 18:46:26 | [diff] [blame] | 19 | #if defined(OS_POSIX) |
| 20 | #include "base/message_pump_libevent.h" |
[email protected] | d680c5c | 2009-05-14 16:44:26 | [diff] [blame] | 21 | #include "base/third_party/valgrind/valgrind.h" |
[email protected] | 36987e9 | 2008-09-18 18:46:26 | [diff] [blame] | 22 | #endif |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 23 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 8fc3a48 | 2008-10-03 16:52:59 | [diff] [blame] | 24 | #include "base/message_pump_glib.h" |
| 25 | #endif |
[email protected] | 36987e9 | 2008-09-18 18:46:26 | [diff] [blame] | 26 | |
[email protected] | e1acf6f | 2008-10-27 20:43:33 | [diff] [blame] | 27 | using base::Time; |
| 28 | using base::TimeDelta; |
| 29 | |
[email protected] | f886b7bf | 2008-09-10 10:54:06 | [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 | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 34 | |
| 35 | //------------------------------------------------------------------------------ |
| 36 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [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. |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 39 | static const int kTaskRunEvent = 0x1; |
| 40 | static const int kTimerEvent = 0x2; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [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 | |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 49 | #if defined(OS_WIN) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 50 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [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 | |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 67 | #endif // defined(OS_WIN) |
| 68 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 69 | //------------------------------------------------------------------------------ |
| 70 | |
[email protected] | f886b7bf | 2008-09-10 10:54:06 | [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. |
[email protected] | 2fdc86a | 2010-01-26 23:08:02 | [diff] [blame] | 75 | // DCHECK(loop) << "Ouch, did you forget to initialize me?"; |
[email protected] | f886b7bf | 2008-09-10 10:54:06 | [diff] [blame] | 76 | return lazy_tls_ptr.Pointer()->Get(); |
| 77 | } |
| 78 | |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 79 | MessageLoop::MessageLoop(Type type) |
| 80 | : type_(type), |
[email protected] | a5b94a9 | 2008-08-12 23:25:43 | [diff] [blame] | 81 | nestable_tasks_allowed_(true), |
[email protected] | b16ef31 | 2008-08-19 18:36:23 | [diff] [blame] | 82 | exception_restoration_(false), |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 83 | state_(NULL), |
| 84 | next_sequence_num_(0) { |
[email protected] | f886b7bf | 2008-09-10 10:54:06 | [diff] [blame] | 85 | DCHECK(!current()) << "should only have one message loop per thread"; |
| 86 | lazy_tls_ptr.Pointer()->Set(this); |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 87 | |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 88 | #if defined(OS_WIN) |
[email protected] | 1a8f5d1d | 2008-09-25 20:33:04 | [diff] [blame] | 89 | // TODO(rvargas): Get rid of the OS guards. |
[email protected] | 9bcbf47 | 2008-08-30 00:22:48 | [diff] [blame] | 90 | if (type_ == TYPE_DEFAULT) { |
| 91 | pump_ = new base::MessagePumpDefault(); |
[email protected] | 1a8f5d1d | 2008-09-25 20:33:04 | [diff] [blame] | 92 | } else if (type_ == TYPE_IO) { |
| 93 | pump_ = new base::MessagePumpForIO(); |
[email protected] | 9bcbf47 | 2008-08-30 00:22:48 | [diff] [blame] | 94 | } else { |
[email protected] | 1a8f5d1d | 2008-09-25 20:33:04 | [diff] [blame] | 95 | DCHECK(type_ == TYPE_UI); |
| 96 | pump_ = new base::MessagePumpForUI(); |
[email protected] | 9bcbf47 | 2008-08-30 00:22:48 | [diff] [blame] | 97 | } |
[email protected] | 36987e9 | 2008-09-18 18:46:26 | [diff] [blame] | 98 | #elif defined(OS_POSIX) |
[email protected] | 96c9ea1 | 2008-09-23 21:08:28 | [diff] [blame] | 99 | if (type_ == TYPE_UI) { |
[email protected] | 8fc3a48 | 2008-10-03 16:52:59 | [diff] [blame] | 100 | #if defined(OS_MACOSX) |
[email protected] | 96c9ea1 | 2008-09-23 21:08:28 | [diff] [blame] | 101 | pump_ = base::MessagePumpMac::Create(); |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 102 | #else |
[email protected] | 8fc3a48 | 2008-10-03 16:52:59 | [diff] [blame] | 103 | pump_ = new base::MessagePumpForUI(); |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 104 | #endif |
[email protected] | 8fc3a48 | 2008-10-03 16:52:59 | [diff] [blame] | 105 | } else if (type_ == TYPE_IO) { |
[email protected] | 36987e9 | 2008-09-18 18:46:26 | [diff] [blame] | 106 | pump_ = new base::MessagePumpLibevent(); |
| 107 | } else { |
| 108 | pump_ = new base::MessagePumpDefault(); |
| 109 | } |
[email protected] | 96c9ea1 | 2008-09-23 21:08:28 | [diff] [blame] | 110 | #endif // OS_POSIX |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | MessageLoop::~MessageLoop() { |
| 114 | DCHECK(this == current()); |
[email protected] | 2a12725 | 2008-08-05 23:16:41 | [diff] [blame] | 115 | |
| 116 | // Let interested parties have one last shot at accessing this. |
| 117 | FOR_EACH_OBSERVER(DestructionObserver, destruction_observers_, |
| 118 | WillDestroyCurrentMessageLoop()); |
| 119 | |
[email protected] | 08de3cde | 2008-09-09 05:55:35 | [diff] [blame] | 120 | DCHECK(!state_); |
| 121 | |
[email protected] | 001747c | 2008-09-10 00:37:07 | [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; |
[email protected] | 08de3cde | 2008-09-09 05:55:35 | [diff] [blame] | 136 | } |
[email protected] | 001747c | 2008-09-10 00:37:07 | [diff] [blame] | 137 | DCHECK(!did_work); |
| 138 | |
| 139 | // OK, now make it so that no one can find us. |
[email protected] | 2b89d22b2 | 2008-09-10 11:14:56 | [diff] [blame] | 140 | lazy_tls_ptr.Pointer()->Set(NULL); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 141 | } |
| 142 | |
[email protected] | 2a12725 | 2008-08-05 23:16:41 | [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 | |
[email protected] | ea15e98 | 2008-08-15 07:31:20 | [diff] [blame] | 153 | void MessageLoop::Run() { |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 154 | AutoRunState save_state(this); |
| 155 | RunHandler(); |
[email protected] | ea15e98 | 2008-08-15 07:31:20 | [diff] [blame] | 156 | } |
| 157 | |
[email protected] | 7e0e876 | 2008-07-31 13:10:20 | [diff] [blame] | 158 | void MessageLoop::RunAllPending() { |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 159 | AutoRunState save_state(this); |
| 160 | state_->quit_received = true; // Means run until we would otherwise block. |
| 161 | RunHandler(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [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. |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 169 | void MessageLoop::RunHandler() { |
| 170 | #if defined(OS_WIN) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 171 | if (exception_restoration_) { |
[email protected] | aff8a13 | 2009-10-26 18:15:59 | [diff] [blame] | 172 | RunInternalInSEHFrame(); |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 173 | return; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 174 | } |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 175 | #endif |
| 176 | |
| 177 | RunInternal(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 178 | } |
[email protected] | aff8a13 | 2009-10-26 18:15:59 | [diff] [blame] | 179 | //------------------------------------------------------------------------------ |
| 180 | #if defined(OS_WIN) |
| 181 | __declspec(noinline) void MessageLoop::RunInternalInSEHFrame() { |
| 182 | LPTOP_LEVEL_EXCEPTION_FILTER current_filter = GetTopSEHFilter(); |
| 183 | __try { |
| 184 | RunInternal(); |
| 185 | } __except(SEHFilter(current_filter)) { |
| 186 | } |
| 187 | return; |
| 188 | } |
| 189 | #endif |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 190 | //------------------------------------------------------------------------------ |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 191 | |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 192 | void MessageLoop::RunInternal() { |
| 193 | DCHECK(this == current()); |
| 194 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 195 | StartHistogrammer(); |
| 196 | |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 197 | #if !defined(OS_MACOSX) |
[email protected] | 148d105 | 2009-07-31 22:53:37 | [diff] [blame] | 198 | if (state_->dispatcher && type() == TYPE_UI) { |
| 199 | static_cast<base::MessagePumpForUI*>(pump_.get())-> |
| 200 | RunWithDispatcher(this, state_->dispatcher); |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 201 | return; |
[email protected] | 7e0e876 | 2008-07-31 13:10:20 | [diff] [blame] | 202 | } |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 203 | #endif |
[email protected] | 1d2eb13 | 2008-12-08 17:36:06 | [diff] [blame] | 204 | |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 205 | pump_->Run(this); |
[email protected] | b8f2fe5d | 2008-07-30 07:50:53 | [diff] [blame] | 206 | } |
[email protected] | 7622bd0 | 2008-07-30 06:58:56 | [diff] [blame] | 207 | |
[email protected] | 3882c433 | 2008-07-30 19:03:59 | [diff] [blame] | 208 | //------------------------------------------------------------------------------ |
| 209 | // Wrapper functions for use in above message loop framework. |
| 210 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 211 | bool MessageLoop::ProcessNextDelayedNonNestableTask() { |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 212 | if (state_->run_depth != 1) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 213 | return false; |
| 214 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 215 | if (deferred_non_nestable_work_queue_.empty()) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 216 | return false; |
[email protected] | 1d2eb13 | 2008-12-08 17:36:06 | [diff] [blame] | 217 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 218 | Task* task = deferred_non_nestable_work_queue_.front().task; |
| 219 | deferred_non_nestable_work_queue_.pop(); |
[email protected] | 1d2eb13 | 2008-12-08 17:36:06 | [diff] [blame] | 220 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 221 | RunTask(task); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 222 | return true; |
| 223 | } |
| 224 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 225 | //------------------------------------------------------------------------------ |
| 226 | |
| 227 | void MessageLoop::Quit() { |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 228 | DCHECK(current() == this); |
| 229 | if (state_) { |
| 230 | state_->quit_received = true; |
| 231 | } else { |
| 232 | NOTREACHED() << "Must be inside Run to call Quit"; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 233 | } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | 781a7ed | 2010-02-23 07:12:22 | [diff] [blame] | 236 | void MessageLoop::QuitNow() { |
| 237 | DCHECK(current() == this); |
| 238 | if (state_) { |
| 239 | pump_->Quit(); |
| 240 | } else { |
| 241 | NOTREACHED() << "Must be inside Run to call Quit"; |
| 242 | } |
| 243 | } |
| 244 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 245 | void MessageLoop::PostTask( |
| 246 | const tracked_objects::Location& from_here, Task* task) { |
| 247 | PostTask_Helper(from_here, task, 0, true); |
| 248 | } |
| 249 | |
| 250 | void MessageLoop::PostDelayedTask( |
[email protected] | 743ace4 | 2009-06-17 17:23:51 | [diff] [blame] | 251 | const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 252 | PostTask_Helper(from_here, task, delay_ms, true); |
| 253 | } |
| 254 | |
| 255 | void MessageLoop::PostNonNestableTask( |
| 256 | const tracked_objects::Location& from_here, Task* task) { |
| 257 | PostTask_Helper(from_here, task, 0, false); |
| 258 | } |
| 259 | |
| 260 | void MessageLoop::PostNonNestableDelayedTask( |
[email protected] | 743ace4 | 2009-06-17 17:23:51 | [diff] [blame] | 261 | const tracked_objects::Location& from_here, Task* task, int64 delay_ms) { |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 262 | PostTask_Helper(from_here, task, delay_ms, false); |
| 263 | } |
| 264 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 265 | // Possibly called on a background thread! |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 266 | void MessageLoop::PostTask_Helper( |
[email protected] | 743ace4 | 2009-06-17 17:23:51 | [diff] [blame] | 267 | const tracked_objects::Location& from_here, Task* task, int64 delay_ms, |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 268 | bool nestable) { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 269 | task->SetBirthPlace(from_here); |
[email protected] | 9bcbf47 | 2008-08-30 00:22:48 | [diff] [blame] | 270 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 271 | PendingTask pending_task(task, nestable); |
[email protected] | 9bcbf47 | 2008-08-30 00:22:48 | [diff] [blame] | 272 | |
| 273 | if (delay_ms > 0) { |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 274 | pending_task.delayed_run_time = |
[email protected] | 9bcbf47 | 2008-08-30 00:22:48 | [diff] [blame] | 275 | Time::Now() + TimeDelta::FromMilliseconds(delay_ms); |
| 276 | } else { |
[email protected] | 2753b39 | 2009-12-28 06:59:52 | [diff] [blame] | 277 | DCHECK_EQ(delay_ms, 0) << "delay should not be negative"; |
[email protected] | 9bcbf47 | 2008-08-30 00:22:48 | [diff] [blame] | 278 | } |
| 279 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 280 | // Warning: Don't try to short-circuit, and handle this thread's tasks more |
| 281 | // directly, as it could starve handling of foreign threads. Put every task |
| 282 | // into this queue. |
| 283 | |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 284 | scoped_refptr<base::MessagePump> pump; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 285 | { |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 286 | AutoLock locked(incoming_queue_lock_); |
| 287 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 288 | bool was_empty = incoming_queue_.empty(); |
| 289 | incoming_queue_.push(pending_task); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 290 | if (!was_empty) |
| 291 | return; // Someone else should have started the sub-pump. |
| 292 | |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 293 | pump = pump_; |
[email protected] | ea15e98 | 2008-08-15 07:31:20 | [diff] [blame] | 294 | } |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 295 | // Since the incoming_queue_ may contain a task that destroys this message |
| 296 | // loop, we cannot exit incoming_queue_lock_ until we are done with |this|. |
| 297 | // We use a stack-based reference to the message pump so that we can call |
| 298 | // ScheduleWork outside of incoming_queue_lock_. |
[email protected] | ea15e98 | 2008-08-15 07:31:20 | [diff] [blame] | 299 | |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 300 | pump->ScheduleWork(); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void MessageLoop::SetNestableTasksAllowed(bool allowed) { |
[email protected] | 124a2bdf | 2008-08-09 00:14:09 | [diff] [blame] | 304 | if (nestable_tasks_allowed_ != allowed) { |
| 305 | nestable_tasks_allowed_ = allowed; |
| 306 | if (!nestable_tasks_allowed_) |
| 307 | return; |
| 308 | // Start the native pump if we are not already pumping. |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 309 | pump_->ScheduleWork(); |
[email protected] | 124a2bdf | 2008-08-09 00:14:09 | [diff] [blame] | 310 | } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | bool MessageLoop::NestableTasksAllowed() const { |
| 314 | return nestable_tasks_allowed_; |
| 315 | } |
| 316 | |
[email protected] | b5f9510 | 2009-07-01 19:53:59 | [diff] [blame] | 317 | bool MessageLoop::IsNested() { |
| 318 | return state_->run_depth > 1; |
| 319 | } |
| 320 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 321 | //------------------------------------------------------------------------------ |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 322 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 323 | void MessageLoop::RunTask(Task* task) { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 324 | DCHECK(nestable_tasks_allowed_); |
| 325 | // Execute the task and assume the worst: It is probably not reentrant. |
| 326 | nestable_tasks_allowed_ = false; |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 327 | |
| 328 | HistogramEvent(kTaskRunEvent); |
| 329 | task->Run(); |
| 330 | delete task; |
| 331 | |
| 332 | nestable_tasks_allowed_ = true; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 333 | } |
| 334 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 335 | bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { |
| 336 | if (pending_task.nestable || state_->run_depth == 1) { |
| 337 | RunTask(pending_task.task); |
| 338 | // Show that we ran a task (Note: a new one might arrive as a |
| 339 | // consequence!). |
| 340 | return true; |
| 341 | } |
| 342 | |
| 343 | // We couldn't run the task now because we're in a nested message loop |
| 344 | // and the task isn't nestable. |
| 345 | deferred_non_nestable_work_queue_.push(pending_task); |
| 346 | return false; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 347 | } |
| 348 | |
[email protected] | 001747c | 2008-09-10 00:37:07 | [diff] [blame] | 349 | void MessageLoop::AddToDelayedWorkQueue(const PendingTask& pending_task) { |
| 350 | // Move to the delayed work queue. Initialize the sequence number |
| 351 | // before inserting into the delayed_work_queue_. The sequence number |
| 352 | // is used to faciliate FIFO sorting when two tasks have the same |
| 353 | // delayed_run_time value. |
| 354 | PendingTask new_pending_task(pending_task); |
| 355 | new_pending_task.sequence_num = next_sequence_num_++; |
| 356 | delayed_work_queue_.push(new_pending_task); |
| 357 | } |
| 358 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 359 | void MessageLoop::ReloadWorkQueue() { |
| 360 | // We can improve performance of our loading tasks from incoming_queue_ to |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 361 | // work_queue_ by waiting until the last minute (work_queue_ is empty) to |
| 362 | // load. That reduces the number of locks-per-task significantly when our |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 363 | // queues get large. |
| 364 | if (!work_queue_.empty()) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 365 | return; // Wait till we *really* need to lock and load. |
| 366 | |
| 367 | // Acquire all we can from the inter-thread queue with one lock acquisition. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 368 | { |
| 369 | AutoLock lock(incoming_queue_lock_); |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 370 | if (incoming_queue_.empty()) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 371 | return; |
[email protected] | b2f0ea1 | 2009-09-02 20:05:21 | [diff] [blame] | 372 | incoming_queue_.Swap(&work_queue_); // Constant time |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 373 | DCHECK(incoming_queue_.empty()); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
[email protected] | 001747c | 2008-09-10 00:37:07 | [diff] [blame] | 377 | bool MessageLoop::DeletePendingTasks() { |
| 378 | bool did_work = !work_queue_.empty(); |
| 379 | while (!work_queue_.empty()) { |
| 380 | PendingTask pending_task = work_queue_.front(); |
| 381 | work_queue_.pop(); |
| 382 | if (!pending_task.delayed_run_time.is_null()) { |
| 383 | // We want to delete delayed tasks in the same order in which they would |
| 384 | // normally be deleted in case of any funny dependencies between delayed |
| 385 | // tasks. |
| 386 | AddToDelayedWorkQueue(pending_task); |
| 387 | } else { |
| 388 | // TODO(darin): Delete all tasks once it is safe to do so. |
[email protected] | d680c5c | 2009-05-14 16:44:26 | [diff] [blame] | 389 | // Until it is totally safe, just do it when running Purify or |
| 390 | // Valgrind. |
[email protected] | 686dd8d | 2009-07-23 22:28:49 | [diff] [blame] | 391 | #if defined(PURIFY) |
[email protected] | 404ec5e | 2009-03-11 20:06:02 | [diff] [blame] | 392 | delete pending_task.task; |
[email protected] | d680c5c | 2009-05-14 16:44:26 | [diff] [blame] | 393 | #elif defined(OS_POSIX) |
| 394 | if (RUNNING_ON_VALGRIND) |
| 395 | delete pending_task.task; |
| 396 | #endif // defined(OS_POSIX) |
[email protected] | 001747c | 2008-09-10 00:37:07 | [diff] [blame] | 397 | } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 398 | } |
[email protected] | 001747c | 2008-09-10 00:37:07 | [diff] [blame] | 399 | did_work |= !deferred_non_nestable_work_queue_.empty(); |
| 400 | while (!deferred_non_nestable_work_queue_.empty()) { |
[email protected] | 2047283 | 2009-03-11 19:46:41 | [diff] [blame] | 401 | // TODO(darin): Delete all tasks once it is safe to do so. |
[email protected] | 686dd8d | 2009-07-23 22:28:49 | [diff] [blame] | 402 | // Until it is totaly safe, only delete them under Purify and Valgrind. |
| 403 | Task* task = NULL; |
| 404 | #if defined(PURIFY) |
| 405 | task = deferred_non_nestable_work_queue_.front().task; |
| 406 | #elif defined(OS_POSIX) |
| 407 | if (RUNNING_ON_VALGRIND) |
| 408 | task = deferred_non_nestable_work_queue_.front().task; |
[email protected] | 8df21d3 | 2009-03-11 19:53:50 | [diff] [blame] | 409 | #endif |
| 410 | deferred_non_nestable_work_queue_.pop(); |
[email protected] | 686dd8d | 2009-07-23 22:28:49 | [diff] [blame] | 411 | if (task) |
| 412 | delete task; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 413 | } |
[email protected] | 001747c | 2008-09-10 00:37:07 | [diff] [blame] | 414 | did_work |= !delayed_work_queue_.empty(); |
| 415 | while (!delayed_work_queue_.empty()) { |
| 416 | Task* task = delayed_work_queue_.top().task; |
| 417 | delayed_work_queue_.pop(); |
| 418 | delete task; |
| 419 | } |
| 420 | return did_work; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 421 | } |
| 422 | |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 423 | bool MessageLoop::DoWork() { |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 424 | if (!nestable_tasks_allowed_) { |
| 425 | // Task can't be executed right now. |
| 426 | return false; |
| 427 | } |
| 428 | |
| 429 | for (;;) { |
| 430 | ReloadWorkQueue(); |
| 431 | if (work_queue_.empty()) |
| 432 | break; |
| 433 | |
| 434 | // Execute oldest task. |
| 435 | do { |
| 436 | PendingTask pending_task = work_queue_.front(); |
| 437 | work_queue_.pop(); |
| 438 | if (!pending_task.delayed_run_time.is_null()) { |
[email protected] | 001747c | 2008-09-10 00:37:07 | [diff] [blame] | 439 | AddToDelayedWorkQueue(pending_task); |
[email protected] | 72deacd | 2008-09-23 19:19:20 | [diff] [blame] | 440 | // If we changed the topmost task, then it is time to re-schedule. |
| 441 | if (delayed_work_queue_.top().task == pending_task.task) |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 442 | pump_->ScheduleDelayedWork(pending_task.delayed_run_time); |
| 443 | } else { |
| 444 | if (DeferOrRunPendingTask(pending_task)) |
| 445 | return true; |
| 446 | } |
| 447 | } while (!work_queue_.empty()); |
| 448 | } |
| 449 | |
| 450 | // Nothing happened. |
| 451 | return false; |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | b24250fc | 2008-08-20 06:30:58 | [diff] [blame] | 454 | bool MessageLoop::DoDelayedWork(Time* next_delayed_work_time) { |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 455 | if (!nestable_tasks_allowed_ || delayed_work_queue_.empty()) { |
| 456 | *next_delayed_work_time = Time(); |
| 457 | return false; |
| 458 | } |
[email protected] | 1d2eb13 | 2008-12-08 17:36:06 | [diff] [blame] | 459 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 460 | if (delayed_work_queue_.top().delayed_run_time > Time::Now()) { |
| 461 | *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time; |
| 462 | return false; |
| 463 | } |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 464 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 465 | PendingTask pending_task = delayed_work_queue_.top(); |
| 466 | delayed_work_queue_.pop(); |
[email protected] | 1d2eb13 | 2008-12-08 17:36:06 | [diff] [blame] | 467 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 468 | if (!delayed_work_queue_.empty()) |
| 469 | *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time; |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 470 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 471 | return DeferOrRunPendingTask(pending_task); |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | bool MessageLoop::DoIdleWork() { |
| 475 | if (ProcessNextDelayedNonNestableTask()) |
| 476 | return true; |
| 477 | |
| 478 | if (state_->quit_received) |
| 479 | pump_->Quit(); |
| 480 | |
| 481 | return false; |
| 482 | } |
| 483 | |
| 484 | //------------------------------------------------------------------------------ |
| 485 | // MessageLoop::AutoRunState |
| 486 | |
| 487 | MessageLoop::AutoRunState::AutoRunState(MessageLoop* loop) : loop_(loop) { |
| 488 | // Make the loop reference us. |
| 489 | previous_state_ = loop_->state_; |
| 490 | if (previous_state_) { |
| 491 | run_depth = previous_state_->run_depth + 1; |
[email protected] | ea15e98 | 2008-08-15 07:31:20 | [diff] [blame] | 492 | } else { |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 493 | run_depth = 1; |
[email protected] | ea15e98 | 2008-08-15 07:31:20 | [diff] [blame] | 494 | } |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 495 | loop_->state_ = this; |
| 496 | |
| 497 | // Initialize the other fields: |
| 498 | quit_received = false; |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 499 | #if !defined(OS_MACOSX) |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 500 | dispatcher = NULL; |
| 501 | #endif |
| 502 | } |
| 503 | |
| 504 | MessageLoop::AutoRunState::~AutoRunState() { |
| 505 | loop_->state_ = previous_state_; |
[email protected] | a5b94a9 | 2008-08-12 23:25:43 | [diff] [blame] | 506 | } |
| 507 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 508 | //------------------------------------------------------------------------------ |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 509 | // MessageLoop::PendingTask |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 510 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 511 | bool MessageLoop::PendingTask::operator<(const PendingTask& other) const { |
| 512 | // Since the top of a priority queue is defined as the "greatest" element, we |
| 513 | // need to invert the comparison here. We want the smaller time to be at the |
| 514 | // top of the heap. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 515 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 516 | if (delayed_run_time < other.delayed_run_time) |
| 517 | return false; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 518 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 519 | if (delayed_run_time > other.delayed_run_time) |
| 520 | return true; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 521 | |
[email protected] | 75257856 | 2008-09-07 08:08:29 | [diff] [blame] | 522 | // If the times happen to match, then we use the sequence number to decide. |
| 523 | // Compare the difference to support integer roll-over. |
| 524 | return (sequence_num - other.sequence_num) > 0; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | //------------------------------------------------------------------------------ |
| 528 | // Method and data for histogramming events and actions taken by each instance |
| 529 | // on each thread. |
| 530 | |
| 531 | // static |
| 532 | bool MessageLoop::enable_histogrammer_ = false; |
| 533 | |
| 534 | // static |
| 535 | void MessageLoop::EnableHistogrammer(bool enable) { |
| 536 | enable_histogrammer_ = enable; |
| 537 | } |
| 538 | |
| 539 | void MessageLoop::StartHistogrammer() { |
| 540 | if (enable_histogrammer_ && !message_histogram_.get() |
| 541 | && StatisticsRecorder::WasStarted()) { |
[email protected] | fc7fb6e | 2008-08-16 03:09:05 | [diff] [blame] | 542 | DCHECK(!thread_name_.empty()); |
[email protected] | 2753b39 | 2009-12-28 06:59:52 | [diff] [blame] | 543 | message_histogram_ = LinearHistogram::FactoryGet("MsgLoop:" + thread_name_, |
| 544 | kLeastNonZeroMessageId, kMaxMessageId, |
| 545 | kNumberOfDistinctMessagesDisplayed, |
| 546 | message_histogram_->kHexRangePrintingFlag); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 547 | message_histogram_->SetRangeDescriptions(event_descriptions_); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | void MessageLoop::HistogramEvent(int event) { |
| 552 | if (message_histogram_.get()) |
| 553 | message_histogram_->Add(event); |
| 554 | } |
| 555 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 556 | // Provide a macro that takes an expression (such as a constant, or macro |
| 557 | // constant) and creates a pair to initalize an array of pairs. In this case, |
| 558 | // our pair consists of the expressions value, and the "stringized" version |
| 559 | // of the expression (i.e., the exrpression put in quotes). For example, if |
| 560 | // we have: |
| 561 | // #define FOO 2 |
| 562 | // #define BAR 5 |
| 563 | // then the following: |
| 564 | // VALUE_TO_NUMBER_AND_NAME(FOO + BAR) |
| 565 | // will expand to: |
| 566 | // {7, "FOO + BAR"} |
| 567 | // We use the resulting array as an argument to our histogram, which reads the |
| 568 | // number as a bucket identifier, and proceeds to use the corresponding name |
| 569 | // in the pair (i.e., the quoted string) when printing out a histogram. |
| 570 | #define VALUE_TO_NUMBER_AND_NAME(name) {name, #name}, |
| 571 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 572 | // static |
| 573 | const LinearHistogram::DescriptionPair MessageLoop::event_descriptions_[] = { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 574 | // Provide some pretty print capability in our histogram for our internal |
| 575 | // messages. |
| 576 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 577 | // A few events we handle (kindred to messages), and used to profile actions. |
| 578 | VALUE_TO_NUMBER_AND_NAME(kTaskRunEvent) |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 579 | VALUE_TO_NUMBER_AND_NAME(kTimerEvent) |
| 580 | |
| 581 | {-1, NULL} // The list must be null terminated, per API to histogram. |
| 582 | }; |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 583 | |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 584 | //------------------------------------------------------------------------------ |
| 585 | // MessageLoopForUI |
| 586 | |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 587 | #if defined(OS_WIN) |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 588 | void MessageLoopForUI::WillProcessMessage(const MSG& message) { |
| 589 | pump_win()->WillProcessMessage(message); |
| 590 | } |
| 591 | void MessageLoopForUI::DidProcessMessage(const MSG& message) { |
| 592 | pump_win()->DidProcessMessage(message); |
| 593 | } |
| 594 | void MessageLoopForUI::PumpOutPendingPaintMessages() { |
[email protected] | 17b8914 | 2008-11-07 21:52:15 | [diff] [blame] | 595 | pump_ui()->PumpOutPendingPaintMessages(); |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | #endif // defined(OS_WIN) |
| 599 | |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 600 | #if !defined(OS_MACOSX) |
[email protected] | 148d105 | 2009-07-31 22:53:37 | [diff] [blame] | 601 | void MessageLoopForUI::AddObserver(Observer* observer) { |
| 602 | pump_ui()->AddObserver(observer); |
| 603 | } |
| 604 | |
| 605 | void MessageLoopForUI::RemoveObserver(Observer* observer) { |
| 606 | pump_ui()->RemoveObserver(observer); |
| 607 | } |
| 608 | |
| 609 | void MessageLoopForUI::Run(Dispatcher* dispatcher) { |
| 610 | AutoRunState save_state(this); |
| 611 | state_->dispatcher = dispatcher; |
| 612 | RunHandler(); |
| 613 | } |
[email protected] | e43eddf1 | 2009-12-29 00:32:52 | [diff] [blame] | 614 | #endif // !defined(OS_MACOSX) |
[email protected] | 148d105 | 2009-07-31 22:53:37 | [diff] [blame] | 615 | |
[email protected] | 4d9bdfaf | 2008-08-26 05:53:57 | [diff] [blame] | 616 | //------------------------------------------------------------------------------ |
| 617 | // MessageLoopForIO |
| 618 | |
| 619 | #if defined(OS_WIN) |
| 620 | |
[email protected] | 32cda29d | 2008-10-09 23:58:43 | [diff] [blame] | 621 | void MessageLoopForIO::RegisterIOHandler(HANDLE file, IOHandler* handler) { |
| 622 | pump_io()->RegisterIOHandler(file, handler); |
| 623 | } |
| 624 | |
[email protected] | 17b8914 | 2008-11-07 21:52:15 | [diff] [blame] | 625 | bool MessageLoopForIO::WaitForIOCompletion(DWORD timeout, IOHandler* filter) { |
| 626 | return pump_io()->WaitForIOCompletion(timeout, filter); |
[email protected] | 32cda29d | 2008-10-09 23:58:43 | [diff] [blame] | 627 | } |
| 628 | |
[email protected] | 36987e9 | 2008-09-18 18:46:26 | [diff] [blame] | 629 | #elif defined(OS_POSIX) |
| 630 | |
[email protected] | e45e6c0 | 2008-12-15 22:02:17 | [diff] [blame] | 631 | bool MessageLoopForIO::WatchFileDescriptor(int fd, |
| 632 | bool persistent, |
| 633 | Mode mode, |
| 634 | FileDescriptorWatcher *controller, |
| 635 | Watcher *delegate) { |
| 636 | return pump_libevent()->WatchFileDescriptor( |
| 637 | fd, |
| 638 | persistent, |
| 639 | static_cast<base::MessagePumpLibevent::Mode>(mode), |
| 640 | controller, |
| 641 | delegate); |
[email protected] | 36987e9 | 2008-09-18 18:46:26 | [diff] [blame] | 642 | } |
| 643 | |
[email protected] | 36987e9 | 2008-09-18 18:46:26 | [diff] [blame] | 644 | #endif |