OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 void MessageLoop::ReloadWorkQueue() { | 387 void MessageLoop::ReloadWorkQueue() { |
388 // We can improve performance of our loading tasks from incoming_queue_ to | 388 // We can improve performance of our loading tasks from incoming_queue_ to |
389 // work_queue_ by waiting until the last minute (work_queue_ is empty) to | 389 // work_queue_ by waiting until the last minute (work_queue_ is empty) to |
390 // load. That reduces the number of locks-per-task significantly when our | 390 // load. That reduces the number of locks-per-task significantly when our |
391 // queues get large. | 391 // queues get large. |
392 if (!work_queue_.empty()) | 392 if (!work_queue_.empty()) |
393 return; // Wait till we *really* need to lock and load. | 393 return; // Wait till we *really* need to lock and load. |
394 | 394 |
395 // Acquire all we can from the inter-thread queue with one lock acquisition. | 395 // Acquire all we can from the inter-thread queue with one lock acquisition. |
396 { | 396 { |
397 AutoLock lock(incoming_queue_lock_); | 397 base::AutoLock lock(incoming_queue_lock_); |
398 if (incoming_queue_.empty()) | 398 if (incoming_queue_.empty()) |
399 return; | 399 return; |
400 incoming_queue_.Swap(&work_queue_); // Constant time | 400 incoming_queue_.Swap(&work_queue_); // Constant time |
401 DCHECK(incoming_queue_.empty()); | 401 DCHECK(incoming_queue_.empty()); |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
405 bool MessageLoop::DeletePendingTasks() { | 405 bool MessageLoop::DeletePendingTasks() { |
406 bool did_work = !work_queue_.empty(); | 406 bool did_work = !work_queue_.empty(); |
407 while (!work_queue_.empty()) { | 407 while (!work_queue_.empty()) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 } | 488 } |
489 } | 489 } |
490 #endif | 490 #endif |
491 | 491 |
492 // Warning: Don't try to short-circuit, and handle this thread's tasks more | 492 // Warning: Don't try to short-circuit, and handle this thread's tasks more |
493 // directly, as it could starve handling of foreign threads. Put every task | 493 // directly, as it could starve handling of foreign threads. Put every task |
494 // into this queue. | 494 // into this queue. |
495 | 495 |
496 scoped_refptr<base::MessagePump> pump; | 496 scoped_refptr<base::MessagePump> pump; |
497 { | 497 { |
498 AutoLock locked(incoming_queue_lock_); | 498 base::AutoLock locked(incoming_queue_lock_); |
499 | 499 |
500 bool was_empty = incoming_queue_.empty(); | 500 bool was_empty = incoming_queue_.empty(); |
501 incoming_queue_.push(pending_task); | 501 incoming_queue_.push(pending_task); |
502 if (!was_empty) | 502 if (!was_empty) |
503 return; // Someone else should have started the sub-pump. | 503 return; // Someone else should have started the sub-pump. |
504 | 504 |
505 pump = pump_; | 505 pump = pump_; |
506 } | 506 } |
507 // Since the incoming_queue_ may contain a task that destroys this message | 507 // Since the incoming_queue_ may contain a task that destroys this message |
508 // loop, we cannot exit incoming_queue_lock_ until we are done with |this|. | 508 // loop, we cannot exit incoming_queue_lock_ until we are done with |this|. |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 Watcher *delegate) { | 696 Watcher *delegate) { |
697 return pump_libevent()->WatchFileDescriptor( | 697 return pump_libevent()->WatchFileDescriptor( |
698 fd, | 698 fd, |
699 persistent, | 699 persistent, |
700 static_cast<base::MessagePumpLibevent::Mode>(mode), | 700 static_cast<base::MessagePumpLibevent::Mode>(mode), |
701 controller, | 701 controller, |
702 delegate); | 702 delegate); |
703 } | 703 } |
704 | 704 |
705 #endif | 705 #endif |
OLD | NEW |