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 : nullptr; | |
29 if (parent_task) { | |
30 task_backtrace[0] = parent_task->posted_from.program_counter(); | |
31 std::copy(parent_task->task_backtrace.begin(), | |
32 parent_task->task_backtrace.begin() + (task_backtrace.size() - 1), | |
danakj
2017/02/09 16:39:51
this is end() - 1 right?
awong
2017/02/09 19:49:02
Yes...initially I thought it was illegal to subtra
| |
33 task_backtrace.begin() + 1); | |
34 } else { | |
35 std::fill(task_backtrace.begin(), task_backtrace.end(), nullptr); | |
36 } | |
37 } | |
30 | 38 |
31 PendingTask::PendingTask(PendingTask&& other) = default; | 39 PendingTask::PendingTask(PendingTask&& other) = default; |
32 | 40 |
33 PendingTask::~PendingTask() { | 41 PendingTask::~PendingTask() { |
34 } | 42 } |
35 | 43 |
36 PendingTask& PendingTask::operator=(PendingTask&& other) = default; | 44 PendingTask& PendingTask::operator=(PendingTask&& other) = default; |
37 | 45 |
38 bool PendingTask::operator<(const PendingTask& other) const { | 46 bool PendingTask::operator<(const PendingTask& other) const { |
39 // Since the top of a priority queue is defined as the "greatest" element, we | 47 // 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 | 48 // need to invert the comparison here. We want the smaller time to be at the |
41 // top of the heap. | 49 // top of the heap. |
42 | 50 |
43 if (delayed_run_time < other.delayed_run_time) | 51 if (delayed_run_time < other.delayed_run_time) |
44 return false; | 52 return false; |
45 | 53 |
46 if (delayed_run_time > other.delayed_run_time) | 54 if (delayed_run_time > other.delayed_run_time) |
47 return true; | 55 return true; |
48 | 56 |
49 // If the times happen to match, then we use the sequence number to decide. | 57 // If the times happen to match, then we use the sequence number to decide. |
50 // Compare the difference to support integer roll-over. | 58 // Compare the difference to support integer roll-over. |
51 return (sequence_num - other.sequence_num) > 0; | 59 return (sequence_num - other.sequence_num) > 0; |
52 } | 60 } |
53 | 61 |
54 } // namespace base | 62 } // namespace base |
OLD | NEW |