[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/pending_task.h" |
| 6 | |
ajwong | 4f13f74 | 2017-02-09 23:52:40 | [diff] [blame] | 7 | #include "base/message_loop/message_loop.h" |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 8 | |
| 9 | namespace base { |
| 10 | |
Brett Wilson | 8e88b31 | 2017-09-12 05:22:16 | [diff] [blame] | 11 | PendingTask::PendingTask(const Location& posted_from, |
tzik | 739ffe3 | 2016-10-14 14:34:58 | [diff] [blame] | 12 | OnceClosure task, |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 13 | TimeTicks delayed_run_time, |
Hajime Hoshi | 64853ef | 2017-10-11 12:56:07 | [diff] [blame] | 14 | Nestable nestable) |
Brett Wilson | b57e3dd | 2017-09-08 00:47:49 | [diff] [blame] | 15 | : task(std::move(task)), |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 16 | posted_from(posted_from), |
Brett Wilson | b57e3dd | 2017-09-08 00:47:49 | [diff] [blame] | 17 | delayed_run_time(delayed_run_time), |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 18 | sequence_num(0), |
cpu | ee890795 | 2014-08-28 23:25:37 | [diff] [blame] | 19 | nestable(nestable), |
ajwong | 4f13f74 | 2017-02-09 23:52:40 | [diff] [blame] | 20 | is_high_res(false) { |
| 21 | const PendingTask* parent_task = |
| 22 | MessageLoop::current() ? MessageLoop::current()->current_pending_task_ |
| 23 | : nullptr; |
| 24 | if (parent_task) { |
| 25 | task_backtrace[0] = parent_task->posted_from.program_counter(); |
| 26 | std::copy(parent_task->task_backtrace.begin(), |
| 27 | parent_task->task_backtrace.end() - 1, |
| 28 | task_backtrace.begin() + 1); |
| 29 | } else { |
| 30 | task_backtrace.fill(nullptr); |
| 31 | } |
| 32 | } |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 33 | |
tzik | b6769d5 | 2016-07-07 20:20:06 | [diff] [blame] | 34 | PendingTask::PendingTask(PendingTask&& other) = default; |
vmpstr | 7c787706 | 2016-02-18 22:12:24 | [diff] [blame] | 35 | |
Chris Watkins | bb7211c | 2017-11-29 07:16:38 | [diff] [blame] | 36 | PendingTask::~PendingTask() = default; |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 37 | |
tzik | b6769d5 | 2016-07-07 20:20:06 | [diff] [blame] | 38 | PendingTask& PendingTask::operator=(PendingTask&& other) = default; |
| 39 | |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 40 | bool PendingTask::operator<(const PendingTask& other) const { |
| 41 | // Since the top of a priority queue is defined as the "greatest" element, we |
| 42 | // need to invert the comparison here. We want the smaller time to be at the |
| 43 | // top of the heap. |
| 44 | |
| 45 | if (delayed_run_time < other.delayed_run_time) |
| 46 | return false; |
| 47 | |
| 48 | if (delayed_run_time > other.delayed_run_time) |
| 49 | return true; |
| 50 | |
| 51 | // If the times happen to match, then we use the sequence number to decide. |
| 52 | // Compare the difference to support integer roll-over. |
| 53 | return (sequence_num - other.sequence_num) > 0; |
| 54 | } |
| 55 | |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 56 | } // namespace base |