• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "base/tracked_objects.h"
8 
9 namespace base {
10 
PendingTask(const tracked_objects::Location & posted_from,base::Closure task)11 PendingTask::PendingTask(const tracked_objects::Location& posted_from,
12                          base::Closure task)
13     : base::TrackingInfo(posted_from, TimeTicks()),
14       task(std::move(task)),
15       posted_from(posted_from),
16       sequence_num(0),
17       nestable(true),
18       is_high_res(false) {
19 }
20 
PendingTask(const tracked_objects::Location & posted_from,base::Closure task,TimeTicks delayed_run_time,bool nestable)21 PendingTask::PendingTask(const tracked_objects::Location& posted_from,
22                          base::Closure task,
23                          TimeTicks delayed_run_time,
24                          bool nestable)
25     : base::TrackingInfo(posted_from, delayed_run_time),
26       task(std::move(task)),
27       posted_from(posted_from),
28       sequence_num(0),
29       nestable(nestable),
30       is_high_res(false) {
31 }
32 
33 PendingTask::PendingTask(PendingTask&& other) = default;
34 
~PendingTask()35 PendingTask::~PendingTask() {
36 }
37 
38 PendingTask& PendingTask::operator=(PendingTask&& other) = default;
39 
operator <(const PendingTask & other) const40 bool PendingTask::operator<(const PendingTask& other) const {
41   // Since the top of a priority queue is defined as the "greatest" element, we
42   // need to invert the comparison here.  We want the smaller time to be at the
43   // top of the heap.
44 
45   if (delayed_run_time < other.delayed_run_time)
46     return false;
47 
48   if (delayed_run_time > other.delayed_run_time)
49     return true;
50 
51   // If the times happen to match, then we use the sequence number to decide.
52   // Compare the difference to support integer roll-over.
53   return (sequence_num - other.sequence_num) > 0;
54 }
55 
56 }  // namespace base
57