OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 123 } |
124 | 124 |
125 //------------------------------------------------------------------------------ | 125 //------------------------------------------------------------------------------ |
126 | 126 |
127 MessageLoop::MessageLoop(Type type) | 127 MessageLoop::MessageLoop(Type type) |
128 : type_(type), | 128 : type_(type), |
129 nestable_tasks_allowed_(true), | 129 nestable_tasks_allowed_(true), |
130 exception_restoration_(false), | 130 exception_restoration_(false), |
131 message_histogram_(NULL), | 131 message_histogram_(NULL), |
132 state_(NULL), | 132 state_(NULL), |
133 should_leak_tasks_(true), | |
134 #ifdef OS_WIN | 133 #ifdef OS_WIN |
135 os_modal_loop_(false), | 134 os_modal_loop_(false), |
136 #endif // OS_WIN | 135 #endif // OS_WIN |
137 next_sequence_num_(0) { | 136 next_sequence_num_(0) { |
138 DCHECK(!current()) << "should only have one message loop per thread"; | 137 DCHECK(!current()) << "should only have one message loop per thread"; |
139 lazy_tls_ptr.Pointer()->Set(this); | 138 lazy_tls_ptr.Pointer()->Set(this); |
140 | 139 |
141 message_loop_proxy_ = new base::MessageLoopProxyImpl(); | 140 message_loop_proxy_ = new base::MessageLoopProxyImpl(); |
142 | 141 |
143 // TODO(rvargas): Get rid of the OS guards. | 142 // TODO(rvargas): Get rid of the OS guards. |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 base::AutoLock lock(incoming_queue_lock_); | 501 base::AutoLock lock(incoming_queue_lock_); |
503 if (incoming_queue_.empty()) | 502 if (incoming_queue_.empty()) |
504 return; | 503 return; |
505 incoming_queue_.Swap(&work_queue_); // Constant time | 504 incoming_queue_.Swap(&work_queue_); // Constant time |
506 DCHECK(incoming_queue_.empty()); | 505 DCHECK(incoming_queue_.empty()); |
507 } | 506 } |
508 } | 507 } |
509 | 508 |
510 bool MessageLoop::DeletePendingTasks() { | 509 bool MessageLoop::DeletePendingTasks() { |
511 bool did_work = !work_queue_.empty(); | 510 bool did_work = !work_queue_.empty(); |
512 // TODO(darin): Delete all tasks once it is safe to do so. | |
513 // Until it is totally safe, just do it when running Valgrind. | |
514 // | |
515 // See http://crbug.com/61131 | |
516 // | |
517 #if defined(USE_HEAPCHECKER) | |
518 should_leak_tasks_ = false; | |
519 #else | |
520 if (RunningOnValgrind()) | |
521 should_leak_tasks_ = false; | |
522 #endif // defined(OS_POSIX) | |
523 while (!work_queue_.empty()) { | 511 while (!work_queue_.empty()) { |
524 PendingTask pending_task = work_queue_.front(); | 512 PendingTask pending_task = work_queue_.front(); |
525 work_queue_.pop(); | 513 work_queue_.pop(); |
526 if (!pending_task.delayed_run_time.is_null()) { | 514 if (!pending_task.delayed_run_time.is_null()) { |
527 // We want to delete delayed tasks in the same order in which they would | 515 // We want to delete delayed tasks in the same order in which they would |
528 // normally be deleted in case of any funny dependencies between delayed | 516 // normally be deleted in case of any funny dependencies between delayed |
529 // tasks. | 517 // tasks. |
530 AddToDelayedWorkQueue(pending_task); | 518 AddToDelayedWorkQueue(pending_task); |
531 } | 519 } |
532 } | 520 } |
533 did_work |= !deferred_non_nestable_work_queue_.empty(); | 521 did_work |= !deferred_non_nestable_work_queue_.empty(); |
534 while (!deferred_non_nestable_work_queue_.empty()) { | 522 while (!deferred_non_nestable_work_queue_.empty()) { |
535 deferred_non_nestable_work_queue_.pop(); | 523 deferred_non_nestable_work_queue_.pop(); |
536 } | 524 } |
537 did_work |= !delayed_work_queue_.empty(); | 525 did_work |= !delayed_work_queue_.empty(); |
538 | 526 |
539 // Historically, we always delete the task regardless of valgrind status. It's | 527 // Historically, we always delete the task regardless of valgrind status. It's |
540 // not completely clear why we want to leak them in the loops above. This | 528 // not completely clear why we want to leak them in the loops above. This |
541 // code is replicating legacy behavior, and should not be considered | 529 // code is replicating legacy behavior, and should not be considered |
542 // absolutely "correct" behavior. See TODO above about deleting all tasks | 530 // absolutely "correct" behavior. See TODO above about deleting all tasks |
543 // when it's safe. | 531 // when it's safe. |
544 should_leak_tasks_ = false; | |
545 while (!delayed_work_queue_.empty()) { | 532 while (!delayed_work_queue_.empty()) { |
546 delayed_work_queue_.pop(); | 533 delayed_work_queue_.pop(); |
547 } | 534 } |
548 should_leak_tasks_ = true; | |
549 return did_work; | 535 return did_work; |
550 } | 536 } |
551 | 537 |
552 TimeTicks MessageLoop::CalculateDelayedRuntime(int64 delay_ms) { | 538 TimeTicks MessageLoop::CalculateDelayedRuntime(int64 delay_ms) { |
553 TimeTicks delayed_run_time; | 539 TimeTicks delayed_run_time; |
554 if (delay_ms > 0) { | 540 if (delay_ms > 0) { |
555 delayed_run_time = | 541 delayed_run_time = |
556 TimeTicks::Now() + TimeDelta::FromMilliseconds(delay_ms); | 542 TimeTicks::Now() + TimeDelta::FromMilliseconds(delay_ms); |
557 | 543 |
558 #if defined(OS_WIN) | 544 #if defined(OS_WIN) |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 Watcher *delegate) { | 793 Watcher *delegate) { |
808 return pump_libevent()->WatchFileDescriptor( | 794 return pump_libevent()->WatchFileDescriptor( |
809 fd, | 795 fd, |
810 persistent, | 796 persistent, |
811 static_cast<base::MessagePumpLibevent::Mode>(mode), | 797 static_cast<base::MessagePumpLibevent::Mode>(mode), |
812 controller, | 798 controller, |
813 delegate); | 799 delegate); |
814 } | 800 } |
815 | 801 |
816 #endif | 802 #endif |
OLD | NEW |