blob: 82ac835da4eab8f19fdfbf25765354ecd7c3ad74 [file] [log] [blame]
[email protected]dd1f9fe2011-11-15 23:36:301// 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]dd1f9fe2011-11-15 23:36:307
8namespace base {
9
Jesse McKenna9cf11372018-11-01 19:38:3810PendingTask::PendingTask() = default;
11
Brett Wilson8e88b312017-09-12 05:22:1612PendingTask::PendingTask(const Location& posted_from,
tzik739ffe32016-10-14 14:34:5813 OnceClosure task,
[email protected]dd1f9fe2011-11-15 23:36:3014 TimeTicks delayed_run_time,
Hajime Hoshi64853ef2017-10-11 12:56:0715 Nestable nestable)
Brett Wilsonb57e3dd2017-09-08 00:47:4916 : task(std::move(task)),
[email protected]dd1f9fe2011-11-15 23:36:3017 posted_from(posted_from),
Brett Wilsonb57e3dd2017-09-08 00:47:4918 delayed_run_time(delayed_run_time),
Gabriel Charetteae4f9ce2018-04-05 19:00:0119 nestable(nestable) {}
[email protected]dd1f9fe2011-11-15 23:36:3020
tzikb6769d52016-07-07 20:20:0621PendingTask::PendingTask(PendingTask&& other) = default;
vmpstr7c7877062016-02-18 22:12:2422
Chris Watkinsbb7211c2017-11-29 07:16:3823PendingTask::~PendingTask() = default;
[email protected]dd1f9fe2011-11-15 23:36:3024
tzikb6769d52016-07-07 20:20:0625PendingTask& PendingTask::operator=(PendingTask&& other) = default;
26
[email protected]dd1f9fe2011-11-15 23:36:3027bool 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]dd1f9fe2011-11-15 23:36:3043} // namespace base