blob: 7f3fccd8827c934f04b42debf5017d407b3bf3fa [file] [log] [blame]
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +09001// 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
danakj0393da32015-03-10 09:31:16 +09005#ifndef BASE_PENDING_TASK_H_
6#define BASE_PENDING_TASK_H_
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +09007
ajwong8d51d072017-02-10 08:52:40 +09008#include <array>
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +09009#include <queue>
10
rsleevi@chromium.org3f19acb2011-11-18 15:08:02 +090011#include "base/base_export.h"
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090012#include "base/callback.h"
13#include "base/location.h"
avi@chromium.orgb45ec932013-06-29 00:14:18 +090014#include "base/time/time.h"
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090015#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.
rsleevi@chromium.org3f19acb2011-11-18 15:08:02 +090021struct BASE_EXPORT PendingTask : public TrackingInfo {
tzike82b7e82016-10-14 23:34:58 +090022 PendingTask(const tracked_objects::Location& posted_from, OnceClosure task);
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090023 PendingTask(const tracked_objects::Location& posted_from,
tzike82b7e82016-10-14 23:34:58 +090024 OnceClosure task,
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090025 TimeTicks delayed_run_time,
26 bool nestable);
tzikc74f6fe2016-07-08 05:20:06 +090027 PendingTask(PendingTask&& other);
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090028 ~PendingTask();
29
tzikc74f6fe2016-07-08 05:20:06 +090030 PendingTask& operator=(PendingTask&& other);
31
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090032 // Used to support sorting.
33 bool operator<(const PendingTask& other) const;
34
35 // The task to run.
tzike82b7e82016-10-14 23:34:58 +090036 OnceClosure task;
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090037
38 // The site this PendingTask was posted from.
39 tracked_objects::Location posted_from;
40
ajwong8d51d072017-02-10 08:52:40 +090041 // Task backtrace.
42 std::array<const void*, 4> task_backtrace;
43
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090044 // Secondary sort key for run time.
45 int sequence_num;
46
47 // OK to dispatch from a nested loop.
48 bool nestable;
cpu410a98e2014-08-29 08:25:37 +090049
50 // Needs high resolution timers.
51 bool is_high_res;
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090052};
53
danakjb82557d2016-06-16 05:47:47 +090054using TaskQueue = std::queue<PendingTask>;
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090055
jhawkins@chromium.org303de232011-11-18 08:26:53 +090056// PendingTasks are sorted by their |delayed_run_time| property.
danakjb82557d2016-06-16 05:47:47 +090057using DelayedTaskQueue = std::priority_queue<base::PendingTask>;
jhawkins@chromium.org303de232011-11-18 08:26:53 +090058
jhawkins@chromium.org2af12f22011-11-16 08:36:30 +090059} // namespace base
60
danakj0393da32015-03-10 09:31:16 +090061#endif // BASE_PENDING_TASK_H_