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