| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 // and deliberately alias it to ensure it is on the stack if the task | 479 // and deliberately alias it to ensure it is on the stack if the task |
| 480 // crashes. Be careful not to assume that the variable itself will have the | 480 // crashes. Be careful not to assume that the variable itself will have the |
| 481 // expected value when displayed by the optimizer in an optimized build. | 481 // expected value when displayed by the optimizer in an optimized build. |
| 482 // Look at a memory dump of the stack. | 482 // Look at a memory dump of the stack. |
| 483 const void* program_counter = | 483 const void* program_counter = |
| 484 pending_task.posted_from.program_counter(); | 484 pending_task.posted_from.program_counter(); |
| 485 base::debug::Alias(&program_counter); | 485 base::debug::Alias(&program_counter); |
| 486 | 486 |
| 487 HistogramEvent(kTaskRunEvent); | 487 HistogramEvent(kTaskRunEvent); |
| 488 | 488 |
| 489 #if defined(TRACK_ALL_TASK_OBJECTS) | 489 tracked_objects::TrackedTime start_time = tracked_objects::ThreadData::Now(); |
| 490 TimeTicks start_of_run = tracked_objects::ThreadData::Now(); | |
| 491 #endif // defined(TRACK_ALL_TASK_OBJECTS) | |
| 492 | 490 |
| 493 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 491 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
| 494 WillProcessTask(pending_task.time_posted)); | 492 WillProcessTask(pending_task.time_posted)); |
| 495 pending_task.task.Run(); | 493 pending_task.task.Run(); |
| 496 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 494 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
| 497 DidProcessTask(pending_task.time_posted)); | 495 DidProcessTask(pending_task.time_posted)); |
| 498 #if defined(TRACK_ALL_TASK_OBJECTS) | 496 |
| 499 tracked_objects::ThreadData::TallyADeathIfActive(pending_task.post_births, | 497 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 500 pending_task.time_posted, pending_task.delayed_run_time, start_of_run, | 498 start_time, tracked_objects::ThreadData::Now()); |
| 501 tracked_objects::ThreadData::Now()); | |
| 502 #endif // defined(TRACK_ALL_TASK_OBJECTS) | |
| 503 | 499 |
| 504 nestable_tasks_allowed_ = true; | 500 nestable_tasks_allowed_ = true; |
| 505 } | 501 } |
| 506 | 502 |
| 507 bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { | 503 bool MessageLoop::DeferOrRunPendingTask(const PendingTask& pending_task) { |
| 508 if (pending_task.nestable || state_->run_depth == 1) { | 504 if (pending_task.nestable || state_->run_depth == 1) { |
| 509 RunTask(pending_task); | 505 RunTask(pending_task); |
| 510 // Show that we ran a task (Note: a new one might arrive as a | 506 // Show that we ran a task (Note: a new one might arrive as a |
| 511 // consequence!). | 507 // consequence!). |
| 512 return true; | 508 return true; |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 768 } |
| 773 | 769 |
| 774 //------------------------------------------------------------------------------ | 770 //------------------------------------------------------------------------------ |
| 775 // MessageLoop::PendingTask | 771 // MessageLoop::PendingTask |
| 776 | 772 |
| 777 MessageLoop::PendingTask::PendingTask( | 773 MessageLoop::PendingTask::PendingTask( |
| 778 const base::Closure& task, | 774 const base::Closure& task, |
| 779 const tracked_objects::Location& posted_from, | 775 const tracked_objects::Location& posted_from, |
| 780 TimeTicks delayed_run_time, | 776 TimeTicks delayed_run_time, |
| 781 bool nestable) | 777 bool nestable) |
| 782 : task(task), | 778 : base::TrackingInfo(posted_from, delayed_run_time), |
| 783 time_posted(TimeTicks::Now()), | 779 task(task), |
| 784 delayed_run_time(delayed_run_time), | |
| 785 posted_from(posted_from), | 780 posted_from(posted_from), |
| 786 sequence_num(0), | 781 sequence_num(0), |
| 787 nestable(nestable) { | 782 nestable(nestable) { |
| 788 #if defined(TRACK_ALL_TASK_OBJECTS) | |
| 789 post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); | |
| 790 #endif // defined(TRACK_ALL_TASK_OBJECTS) | |
| 791 } | 783 } |
| 792 | 784 |
| 793 MessageLoop::PendingTask::~PendingTask() { | 785 MessageLoop::PendingTask::~PendingTask() { |
| 794 } | 786 } |
| 795 | 787 |
| 796 bool MessageLoop::PendingTask::operator<(const PendingTask& other) const { | 788 bool MessageLoop::PendingTask::operator<(const PendingTask& other) const { |
| 797 // Since the top of a priority queue is defined as the "greatest" element, we | 789 // Since the top of a priority queue is defined as the "greatest" element, we |
| 798 // need to invert the comparison here. We want the smaller time to be at the | 790 // need to invert the comparison here. We want the smaller time to be at the |
| 799 // top of the heap. | 791 // top of the heap. |
| 800 | 792 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 Watcher *delegate) { | 863 Watcher *delegate) { |
| 872 return pump_libevent()->WatchFileDescriptor( | 864 return pump_libevent()->WatchFileDescriptor( |
| 873 fd, | 865 fd, |
| 874 persistent, | 866 persistent, |
| 875 static_cast<base::MessagePumpLibevent::Mode>(mode), | 867 static_cast<base::MessagePumpLibevent::Mode>(mode), |
| 876 controller, | 868 controller, |
| 877 delegate); | 869 delegate); |
| 878 } | 870 } |
| 879 | 871 |
| 880 #endif | 872 #endif |
| OLD | NEW |