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 | |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 7 | |
| 8 | namespace base { |
| 9 | |
Brett Wilson | 89388db | 2017-09-12 14:22:16 +0900 | [diff] [blame] | 10 | PendingTask::PendingTask(const Location& posted_from, |
tzik | e82b7e8 | 2016-10-14 23:34:58 +0900 | [diff] [blame] | 11 | OnceClosure task, |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 12 | TimeTicks delayed_run_time, |
Hajime Hoshi | 67c2dbe | 2017-10-11 21:56:07 +0900 | [diff] [blame] | 13 | Nestable nestable) |
Brett Wilson | c7c59cb | 2017-09-08 09:47:49 +0900 | [diff] [blame] | 14 | : task(std::move(task)), |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 15 | posted_from(posted_from), |
Brett Wilson | c7c59cb | 2017-09-08 09:47:49 +0900 | [diff] [blame] | 16 | delayed_run_time(delayed_run_time), |
Gabriel Charette | c3cf7da | 2018-04-06 04:00:01 +0900 | [diff] [blame] | 17 | nestable(nestable) {} |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 18 | |
tzik | c74f6fe | 2016-07-08 05:20:06 +0900 | [diff] [blame] | 19 | PendingTask::PendingTask(PendingTask&& other) = default; |
vmpstr | db00479 | 2016-02-19 07:12:24 +0900 | [diff] [blame] | 20 | |
Chris Watkins | d155d9f | 2017-11-29 16:16:38 +0900 | [diff] [blame] | 21 | PendingTask::~PendingTask() = default; |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 22 | |
tzik | c74f6fe | 2016-07-08 05:20:06 +0900 | [diff] [blame] | 23 | PendingTask& PendingTask::operator=(PendingTask&& other) = default; |
| 24 | |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 25 | bool PendingTask::operator<(const PendingTask& other) const { |
| 26 | // Since the top of a priority queue is defined as the "greatest" element, we |
| 27 | // need to invert the comparison here. We want the smaller time to be at the |
| 28 | // top of the heap. |
| 29 | |
| 30 | if (delayed_run_time < other.delayed_run_time) |
| 31 | return false; |
| 32 | |
| 33 | if (delayed_run_time > other.delayed_run_time) |
| 34 | return true; |
| 35 | |
| 36 | // If the times happen to match, then we use the sequence number to decide. |
| 37 | // Compare the difference to support integer roll-over. |
| 38 | return (sequence_num - other.sequence_num) > 0; |
| 39 | } |
| 40 | |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 41 | } // namespace base |