| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 // load. That reduces the number of locks-per-task significantly when our | 347 // load. That reduces the number of locks-per-task significantly when our |
| 348 // queues get large. | 348 // queues get large. |
| 349 if (!work_queue_.empty()) | 349 if (!work_queue_.empty()) |
| 350 return; // Wait till we *really* need to lock and load. | 350 return; // Wait till we *really* need to lock and load. |
| 351 | 351 |
| 352 // Acquire all we can from the inter-thread queue with one lock acquisition. | 352 // Acquire all we can from the inter-thread queue with one lock acquisition. |
| 353 { | 353 { |
| 354 AutoLock lock(incoming_queue_lock_); | 354 AutoLock lock(incoming_queue_lock_); |
| 355 if (incoming_queue_.empty()) | 355 if (incoming_queue_.empty()) |
| 356 return; | 356 return; |
| 357 std::swap(incoming_queue_, work_queue_); | 357 incoming_queue_.Swap(&work_queue_); // Constant time |
| 358 DCHECK(incoming_queue_.empty()); | 358 DCHECK(incoming_queue_.empty()); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 bool MessageLoop::DeletePendingTasks() { | 362 bool MessageLoop::DeletePendingTasks() { |
| 363 bool did_work = !work_queue_.empty(); | 363 bool did_work = !work_queue_.empty(); |
| 364 while (!work_queue_.empty()) { | 364 while (!work_queue_.empty()) { |
| 365 PendingTask pending_task = work_queue_.front(); | 365 PendingTask pending_task = work_queue_.front(); |
| 366 work_queue_.pop(); | 366 work_queue_.pop(); |
| 367 if (!pending_task.delayed_run_time.is_null()) { | 367 if (!pending_task.delayed_run_time.is_null()) { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 Watcher *delegate) { | 622 Watcher *delegate) { |
| 623 return pump_libevent()->WatchFileDescriptor( | 623 return pump_libevent()->WatchFileDescriptor( |
| 624 fd, | 624 fd, |
| 625 persistent, | 625 persistent, |
| 626 static_cast<base::MessagePumpLibevent::Mode>(mode), | 626 static_cast<base::MessagePumpLibevent::Mode>(mode), |
| 627 controller, | 627 controller, |
| 628 delegate); | 628 delegate); |
| 629 } | 629 } |
| 630 | 630 |
| 631 #endif | 631 #endif |
| OLD | NEW |