blob: 35724eadfd5067db47b89ff309c4acfce257829d [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#include "base/tracking_info.h"
16
17namespace base {
18
19// Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue
20// for use by classes that queue and execute tasks.
[email protected]c360bae72011-11-18 06:08:0221struct BASE_EXPORT PendingTask : public TrackingInfo {
tzik739ffe32016-10-14 14:34:5822 PendingTask(const tracked_objects::Location& posted_from, OnceClosure task);
[email protected]dd1f9fe2011-11-15 23:36:3023 PendingTask(const tracked_objects::Location& posted_from,
tzik739ffe32016-10-14 14:34:5824 OnceClosure task,
[email protected]dd1f9fe2011-11-15 23:36:3025 TimeTicks delayed_run_time,
26 bool nestable);
tzikb6769d52016-07-07 20:20:0627 PendingTask(PendingTask&& other);
[email protected]dd1f9fe2011-11-15 23:36:3028 ~PendingTask();
29
tzikb6769d52016-07-07 20:20:0630 PendingTask& operator=(PendingTask&& other);
31
[email protected]dd1f9fe2011-11-15 23:36:3032 // Used to support sorting.
33 bool operator<(const PendingTask& other) const;
34
35 // The task to run.
tzik739ffe32016-10-14 14:34:5836 OnceClosure task;
[email protected]dd1f9fe2011-11-15 23:36:3037
38 // The site this PendingTask was posted from.
39 tracked_objects::Location posted_from;
40
ajwong4f13f742017-02-09 23:52:4041 // Task backtrace.
42 std::array<const void*, 4> task_backtrace;
43
[email protected]dd1f9fe2011-11-15 23:36:3044 // Secondary sort key for run time.
45 int sequence_num;
46
47 // OK to dispatch from a nested loop.
48 bool nestable;
cpuee8907952014-08-28 23:25:3749
50 // Needs high resolution timers.
51 bool is_high_res;
[email protected]dd1f9fe2011-11-15 23:36:3052};
53
Brett Wilson3d88e7762017-08-14 19:54:3854using TaskQueue = base::queue<PendingTask>;
[email protected]dd1f9fe2011-11-15 23:36:3055
[email protected]262060ff2011-11-17 23:26:5356// PendingTasks are sorted by their |delayed_run_time| property.
danakj5d792152016-06-15 20:47:4757using DelayedTaskQueue = std::priority_queue<base::PendingTask>;
[email protected]262060ff2011-11-17 23:26:5358
[email protected]dd1f9fe2011-11-15 23:36:3059} // namespace base
60
danakj0a448602015-03-10 00:31:1661#endif // BASE_PENDING_TASK_H_