blob: 50924fdda36b974d505b29590548da56c94ee7b9 [file] [log] [blame]
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +09001// 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.org2af12f22011-11-16 08:36:30 +09007
8namespace base {
9
Brett Wilson89388db2017-09-12 14:22:16 +090010PendingTask::PendingTask(const Location& posted_from,
tzike82b7e82016-10-14 23:34:58 +090011 OnceClosure task,
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090012 TimeTicks delayed_run_time,
Hajime Hoshi67c2dbe2017-10-11 21:56:07 +090013 Nestable nestable)
Brett Wilsonc7c59cb2017-09-08 09:47:49 +090014 : task(std::move(task)),
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090015 posted_from(posted_from),
Brett Wilsonc7c59cb2017-09-08 09:47:49 +090016 delayed_run_time(delayed_run_time),
Gabriel Charettec3cf7da2018-04-06 04:00:01 +090017 nestable(nestable) {}
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090018
tzikc74f6fe2016-07-08 05:20:06 +090019PendingTask::PendingTask(PendingTask&& other) = default;
vmpstrdb004792016-02-19 07:12:24 +090020
Chris Watkinsd155d9f2017-11-29 16:16:38 +090021PendingTask::~PendingTask() = default;
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090022
tzikc74f6fe2016-07-08 05:20:06 +090023PendingTask& PendingTask::operator=(PendingTask&& other) = default;
24
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090025bool 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.org2af12f22011-11-16 08:36:30 +090041} // namespace base