| 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/pending_task.h" | 5 #include "base/pending_task.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" |
| 7 #include "base/tracked_objects.h" | 8 #include "base/tracked_objects.h" |
| 8 | 9 |
| 9 namespace base { | 10 namespace base { |
| 10 | 11 |
| 11 PendingTask::PendingTask(const tracked_objects::Location& posted_from, | 12 PendingTask::PendingTask(const tracked_objects::Location& posted_from, |
| 12 OnceClosure task) | 13 OnceClosure task) |
| 13 : base::TrackingInfo(posted_from, TimeTicks()), | 14 : PendingTask(posted_from, std::move(task), TimeTicks(), true) {} |
| 14 task(std::move(task)), | |
| 15 posted_from(posted_from), | |
| 16 sequence_num(0), | |
| 17 nestable(true), | |
| 18 is_high_res(false) {} | |
| 19 | 15 |
| 20 PendingTask::PendingTask(const tracked_objects::Location& posted_from, | 16 PendingTask::PendingTask(const tracked_objects::Location& posted_from, |
| 21 OnceClosure task, | 17 OnceClosure task, |
| 22 TimeTicks delayed_run_time, | 18 TimeTicks delayed_run_time, |
| 23 bool nestable) | 19 bool nestable) |
| 24 : base::TrackingInfo(posted_from, delayed_run_time), | 20 : base::TrackingInfo(posted_from, delayed_run_time), |
| 25 task(std::move(task)), | 21 task(std::move(task)), |
| 26 posted_from(posted_from), | 22 posted_from(posted_from), |
| 27 sequence_num(0), | 23 sequence_num(0), |
| 28 nestable(nestable), | 24 nestable(nestable), |
| 29 is_high_res(false) {} | 25 is_high_res(false) { |
| 26 const PendingTask* parent_task = |
| 27 MessageLoop::current() ? MessageLoop::current()->current_pending_task_ |
| 28 : NULL; |
| 29 task_backtrace[0] = posted_from.program_counter(); |
| 30 if (parent_task) { |
| 31 memcpy(&task_backtrace[1], &parent_task->task_backtrace[0], |
| 32 sizeof(task_backtrace[0]) * (arraysize(task_backtrace) - 1)); |
| 33 } |
| 34 } |
| 30 | 35 |
| 31 PendingTask::PendingTask(PendingTask&& other) = default; | 36 PendingTask::PendingTask(PendingTask&& other) = default; |
| 32 | 37 |
| 33 PendingTask::~PendingTask() { | 38 PendingTask::~PendingTask() { |
| 34 } | 39 } |
| 35 | 40 |
| 36 PendingTask& PendingTask::operator=(PendingTask&& other) = default; | 41 PendingTask& PendingTask::operator=(PendingTask&& other) = default; |
| 37 | 42 |
| 38 bool PendingTask::operator<(const PendingTask& other) const { | 43 bool PendingTask::operator<(const PendingTask& other) const { |
| 39 // Since the top of a priority queue is defined as the "greatest" element, we | 44 // Since the top of a priority queue is defined as the "greatest" element, we |
| 40 // need to invert the comparison here. We want the smaller time to be at the | 45 // need to invert the comparison here. We want the smaller time to be at the |
| 41 // top of the heap. | 46 // top of the heap. |
| 42 | 47 |
| 43 if (delayed_run_time < other.delayed_run_time) | 48 if (delayed_run_time < other.delayed_run_time) |
| 44 return false; | 49 return false; |
| 45 | 50 |
| 46 if (delayed_run_time > other.delayed_run_time) | 51 if (delayed_run_time > other.delayed_run_time) |
| 47 return true; | 52 return true; |
| 48 | 53 |
| 49 // If the times happen to match, then we use the sequence number to decide. | 54 // If the times happen to match, then we use the sequence number to decide. |
| 50 // Compare the difference to support integer roll-over. | 55 // Compare the difference to support integer roll-over. |
| 51 return (sequence_num - other.sequence_num) > 0; | 56 return (sequence_num - other.sequence_num) > 0; |
| 52 } | 57 } |
| 53 | 58 |
| 54 } // namespace base | 59 } // namespace base |
| OLD | NEW |