blob: 8c7854b14cb0188c6f4b13c350d08066d84f730e [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
danakj0a448602015-03-10 00:31:165#ifndef BASE_PENDING_TASK_H_
6#define BASE_PENDING_TASK_H_
[email protected]dd1f9fe2011-11-15 23:36:307
ajwong4f13f742017-02-09 23:52:408#include <array>
[email protected]dd1f9fe2011-11-15 23:36:309
[email protected]c360bae72011-11-18 06:08:0210#include "base/base_export.h"
[email protected]dd1f9fe2011-11-15 23:36:3011#include "base/callback.h"
Brett Wilson3d88e7762017-08-14 19:54:3812#include "base/containers/queue.h"
[email protected]dd1f9fe2011-11-15 23:36:3013#include "base/location.h"
[email protected]8f9a3a52013-06-28 15:14:1814#include "base/time/time.h"
[email protected]dd1f9fe2011-11-15 23:36:3015
16namespace base {
17
Hajime Hoshi64853ef2017-10-11 12:56:0718enum class Nestable {
19 kNonNestable,
20 kNestable,
21};
22
[email protected]dd1f9fe2011-11-15 23:36:3023// Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue
24// for use by classes that queue and execute tasks.
Brett Wilsonb57e3dd2017-09-08 00:47:4925struct BASE_EXPORT PendingTask {
Brett Wilson8e88b312017-09-12 05:22:1626 PendingTask(const Location& posted_from,
tzik739ffe32016-10-14 14:34:5827 OnceClosure task,
Hajime Hoshi64853ef2017-10-11 12:56:0728 TimeTicks delayed_run_time = TimeTicks(),
29 Nestable nestable = Nestable::kNestable);
tzikb6769d52016-07-07 20:20:0630 PendingTask(PendingTask&& other);
[email protected]dd1f9fe2011-11-15 23:36:3031 ~PendingTask();
32
tzikb6769d52016-07-07 20:20:0633 PendingTask& operator=(PendingTask&& other);
34
[email protected]dd1f9fe2011-11-15 23:36:3035 // Used to support sorting.
36 bool operator<(const PendingTask& other) const;
37
38 // The task to run.
tzik739ffe32016-10-14 14:34:5839 OnceClosure task;
[email protected]dd1f9fe2011-11-15 23:36:3040
41 // The site this PendingTask was posted from.
Brett Wilson8e88b312017-09-12 05:22:1642 Location posted_from;
[email protected]dd1f9fe2011-11-15 23:36:3043
Brett Wilsonb57e3dd2017-09-08 00:47:4944 // The time when the task should be run.
45 base::TimeTicks delayed_run_time;
46
ajwong4f13f742017-02-09 23:52:4047 // Task backtrace.
48 std::array<const void*, 4> task_backtrace;
49
[email protected]dd1f9fe2011-11-15 23:36:3050 // Secondary sort key for run time.
51 int sequence_num;
52
53 // OK to dispatch from a nested loop.
Hajime Hoshi64853ef2017-10-11 12:56:0754 Nestable nestable;
cpuee8907952014-08-28 23:25:3755
56 // Needs high resolution timers.
57 bool is_high_res;
[email protected]dd1f9fe2011-11-15 23:36:3058};
59
Brett Wilson3d88e7762017-08-14 19:54:3860using TaskQueue = base::queue<PendingTask>;
[email protected]dd1f9fe2011-11-15 23:36:3061
[email protected]262060ff2011-11-17 23:26:5362// PendingTasks are sorted by their |delayed_run_time| property.
danakj5d792152016-06-15 20:47:4763using DelayedTaskQueue = std::priority_queue<base::PendingTask>;
[email protected]262060ff2011-11-17 23:26:5364
[email protected]dd1f9fe2011-11-15 23:36:3065} // namespace base
66
danakj0a448602015-03-10 00:31:1667#endif // BASE_PENDING_TASK_H_