| 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" |
| 11 #include "base/debug/alias.h" |
| 11 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/message_pump_default.h" | 14 #include "base/message_pump_default.h" |
| 14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 15 #include "base/scoped_ptr.h" | 16 #include "base/scoped_ptr.h" |
| 16 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 17 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 17 #include "base/threading/thread_local.h" | 18 #include "base/threading/thread_local.h" |
| 18 #include "base/time.h" | 19 #include "base/time.h" |
| 19 #include "base/tracked_objects.h" | 20 #include "base/tracked_objects.h" |
| 20 | 21 |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 | 461 |
| 461 RunTask(pending_task); | 462 RunTask(pending_task); |
| 462 return true; | 463 return true; |
| 463 } | 464 } |
| 464 | 465 |
| 465 void MessageLoop::RunTask(const PendingTask& pending_task) { | 466 void MessageLoop::RunTask(const PendingTask& pending_task) { |
| 466 DCHECK(nestable_tasks_allowed_); | 467 DCHECK(nestable_tasks_allowed_); |
| 467 // Execute the task and assume the worst: It is probably not reentrant. | 468 // Execute the task and assume the worst: It is probably not reentrant. |
| 468 nestable_tasks_allowed_ = false; | 469 nestable_tasks_allowed_ = false; |
| 469 | 470 |
| 471 // Before running the task, store the program counter where it was posted |
| 472 // and deliberately alias it to ensure it is on the stack if the task |
| 473 // crashes. Be careful not to assume that the variable itself will have the |
| 474 // expected value when displayed by the optimizer in an optimized build. |
| 475 // Look at a memory dump of the stack. |
| 476 const void* program_counter = pending_task.birth_program_counter; |
| 477 base::debug::Alias(&program_counter); |
| 478 |
| 470 HistogramEvent(kTaskRunEvent); | 479 HistogramEvent(kTaskRunEvent); |
| 471 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 480 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
| 472 WillProcessTask(pending_task.time_posted)); | 481 WillProcessTask(pending_task.time_posted)); |
| 473 pending_task.task.Run(); | 482 pending_task.task.Run(); |
| 474 FOR_EACH_OBSERVER(TaskObserver, task_observers_, | 483 FOR_EACH_OBSERVER(TaskObserver, task_observers_, |
| 475 DidProcessTask(pending_task.time_posted)); | 484 DidProcessTask(pending_task.time_posted)); |
| 476 | 485 |
| 477 #if defined(TRACK_ALL_TASK_OBJECTS) | 486 #if defined(TRACK_ALL_TASK_OBJECTS) |
| 478 if (tracked_objects::ThreadData::IsActive() && pending_task.post_births) { | 487 if (tracked_objects::ThreadData::IsActive() && pending_task.post_births) { |
| 479 tracked_objects::ThreadData::current()->TallyADeath( | 488 tracked_objects::ThreadData::current()->TallyADeath( |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 | 768 |
| 760 MessageLoop::PendingTask::PendingTask( | 769 MessageLoop::PendingTask::PendingTask( |
| 761 const base::Closure& task, | 770 const base::Closure& task, |
| 762 const tracked_objects::Location& posted_from, | 771 const tracked_objects::Location& posted_from, |
| 763 TimeTicks delayed_run_time, | 772 TimeTicks delayed_run_time, |
| 764 bool nestable) | 773 bool nestable) |
| 765 : task(task), | 774 : task(task), |
| 766 time_posted(TimeTicks::Now()), | 775 time_posted(TimeTicks::Now()), |
| 767 delayed_run_time(delayed_run_time), | 776 delayed_run_time(delayed_run_time), |
| 768 sequence_num(0), | 777 sequence_num(0), |
| 769 nestable(nestable) { | 778 nestable(nestable), |
| 779 birth_program_counter(posted_from.program_counter()) { |
| 770 #if defined(TRACK_ALL_TASK_OBJECTS) | 780 #if defined(TRACK_ALL_TASK_OBJECTS) |
| 771 if (tracked_objects::ThreadData::IsActive()) { | 781 if (tracked_objects::ThreadData::IsActive()) { |
| 772 tracked_objects::ThreadData* current_thread_data = | 782 tracked_objects::ThreadData* current_thread_data = |
| 773 tracked_objects::ThreadData::current(); | 783 tracked_objects::ThreadData::current(); |
| 774 if (current_thread_data) { | 784 if (current_thread_data) { |
| 775 post_births = current_thread_data->TallyABirth(posted_from); | 785 post_births = current_thread_data->TallyABirth(posted_from); |
| 776 } else { | 786 } else { |
| 777 // Shutdown started, and this thread wasn't registered. | 787 // Shutdown started, and this thread wasn't registered. |
| 778 post_births = NULL; | 788 post_births = NULL; |
| 779 } | 789 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 Watcher *delegate) { | 863 Watcher *delegate) { |
| 854 return pump_libevent()->WatchFileDescriptor( | 864 return pump_libevent()->WatchFileDescriptor( |
| 855 fd, | 865 fd, |
| 856 persistent, | 866 persistent, |
| 857 static_cast<base::MessagePumpLibevent::Mode>(mode), | 867 static_cast<base::MessagePumpLibevent::Mode>(mode), |
| 858 controller, | 868 controller, |
| 859 delegate); | 869 delegate); |
| 860 } | 870 } |
| 861 | 871 |
| 862 #endif | 872 #endif |
| OLD | NEW |