jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [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 | 8d51d07 | 2017-02-10 08:52:40 +0900 | [diff] [blame] | 7 | #include "base/message_loop/message_loop.h" |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 8 | |
| 9 | namespace base { |
| 10 | |
Brett Wilson | 89388db | 2017-09-12 14:22:16 +0900 | [diff] [blame] | 11 | PendingTask::PendingTask(const Location& posted_from, |
tzik | e82b7e8 | 2016-10-14 23:34:58 +0900 | [diff] [blame] | 12 | OnceClosure task, |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 13 | TimeTicks delayed_run_time, |
Hajime Hoshi | 67c2dbe | 2017-10-11 21:56:07 +0900 | [diff] [blame^] | 14 | Nestable nestable) |
Brett Wilson | c7c59cb | 2017-09-08 09:47:49 +0900 | [diff] [blame] | 15 | : task(std::move(task)), |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 16 | posted_from(posted_from), |
Brett Wilson | c7c59cb | 2017-09-08 09:47:49 +0900 | [diff] [blame] | 17 | delayed_run_time(delayed_run_time), |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 18 | sequence_num(0), |
cpu | 410a98e | 2014-08-29 08:25:37 +0900 | [diff] [blame] | 19 | nestable(nestable), |
ajwong | 8d51d07 | 2017-02-10 08:52:40 +0900 | [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 | } |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 33 | |
tzik | c74f6fe | 2016-07-08 05:20:06 +0900 | [diff] [blame] | 34 | PendingTask::PendingTask(PendingTask&& other) = default; |
vmpstr | db00479 | 2016-02-19 07:12:24 +0900 | [diff] [blame] | 35 | |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 36 | PendingTask::~PendingTask() { |
| 37 | } |
| 38 | |
tzik | c74f6fe | 2016-07-08 05:20:06 +0900 | [diff] [blame] | 39 | PendingTask& PendingTask::operator=(PendingTask&& other) = default; |
| 40 | |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 41 | bool PendingTask::operator<(const PendingTask& other) const { |
| 42 | // Since the top of a priority queue is defined as the "greatest" element, we |
| 43 | // need to invert the comparison here. We want the smaller time to be at the |
| 44 | // top of the heap. |
| 45 | |
| 46 | if (delayed_run_time < other.delayed_run_time) |
| 47 | return false; |
| 48 | |
| 49 | if (delayed_run_time > other.delayed_run_time) |
| 50 | return true; |
| 51 | |
| 52 | // If the times happen to match, then we use the sequence number to decide. |
| 53 | // Compare the difference to support integer roll-over. |
| 54 | return (sequence_num - other.sequence_num) > 0; |
| 55 | } |
| 56 | |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 57 | } // namespace base |