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.
5 #include "base/pending_task.h"
7 #include "base/tracked_objects.h"
11 PendingTask::PendingTask(const tracked_objects::Location
& posted_from
,
12 const base::Closure
& task
)
13 : base::TrackingInfo(posted_from
, TimeTicks()),
15 posted_from(posted_from
),
21 PendingTask::PendingTask(const tracked_objects::Location
& posted_from
,
22 const base::Closure
& task
,
23 TimeTicks delayed_run_time
,
25 : base::TrackingInfo(posted_from
, delayed_run_time
),
27 posted_from(posted_from
),
33 PendingTask::~PendingTask() {
36 bool PendingTask::operator<(const PendingTask
& other
) const {
37 // Since the top of a priority queue is defined as the "greatest" element, we
38 // need to invert the comparison here. We want the smaller time to be at the
41 if (delayed_run_time
< other
.delayed_run_time
)
44 if (delayed_run_time
> other
.delayed_run_time
)
47 // If the times happen to match, then we use the sequence number to decide.
48 // Compare the difference to support integer roll-over.
49 return (sequence_num
- other
.sequence_num
) > 0;
52 void TaskQueue::Swap(TaskQueue
* queue
) {
53 c
.swap(queue
->c
); // Calls std::deque::swap.