blob: 31f2d2d9beb764079eb884f21c0b50260f8fb46d [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
ajwong4f13f742017-02-09 23:52:407#include "base/message_loop/message_loop.h"
[email protected]dd1f9fe2011-11-15 23:36:308
9namespace base {
10
Brett Wilson8e88b312017-09-12 05:22:1611PendingTask::PendingTask(const Location& posted_from,
tzik739ffe32016-10-14 14:34:5812 OnceClosure task,
[email protected]dd1f9fe2011-11-15 23:36:3013 TimeTicks delayed_run_time,
Hajime Hoshi64853ef2017-10-11 12:56:0714 Nestable nestable)
Brett Wilsonb57e3dd2017-09-08 00:47:4915 : task(std::move(task)),
[email protected]dd1f9fe2011-11-15 23:36:3016 posted_from(posted_from),
Brett Wilsonb57e3dd2017-09-08 00:47:4917 delayed_run_time(delayed_run_time),
[email protected]dd1f9fe2011-11-15 23:36:3018 sequence_num(0),
cpuee8907952014-08-28 23:25:3719 nestable(nestable),
ajwong4f13f742017-02-09 23:52:4020 is_high_res(false) {
21 const PendingTask* parent_task =
22 MessageLoop::current() ? MessageLoop::current()->current_pending_task_
23 : nullptr;
24 if (parent_task) {
25 task_backtrace[0] = parent_task->posted_from.program_counter();
26 std::copy(parent_task->task_backtrace.begin(),
27 parent_task->task_backtrace.end() - 1,
28 task_backtrace.begin() + 1);
29 } else {
30 task_backtrace.fill(nullptr);
31 }
32}
[email protected]dd1f9fe2011-11-15 23:36:3033
tzikb6769d52016-07-07 20:20:0634PendingTask::PendingTask(PendingTask&& other) = default;
vmpstr7c7877062016-02-18 22:12:2435
Chris Watkinsbb7211c2017-11-29 07:16:3836PendingTask::~PendingTask() = default;
[email protected]dd1f9fe2011-11-15 23:36:3037
tzikb6769d52016-07-07 20:20:0638PendingTask& PendingTask::operator=(PendingTask&& other) = default;
39
[email protected]dd1f9fe2011-11-15 23:36:3040bool 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
[email protected]dd1f9fe2011-11-15 23:36:3056} // namespace base