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 7 8 namespace base { 9 10 PendingTask::PendingTask(const Location& posted_from, 11 OnceClosure task, 12 TimeTicks delayed_run_time, 13 Nestable nestable) 14 : task(std::move(task)), 15 posted_from(posted_from), 16 delayed_run_time(delayed_run_time), 17 nestable(nestable) {} 18 19 PendingTask::PendingTask(PendingTask&& other) = default; 20 21 PendingTask::~PendingTask() = default; 22 23 PendingTask& PendingTask::operator=(PendingTask&& other) = default; 24 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 41 } // namespace base 42