[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 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. |
| 4 | |
danakj | 0a44860 | 2015-03-10 00:31:16 | [diff] [blame] | 5 | #ifndef BASE_PENDING_TASK_H_ |
| 6 | #define BASE_PENDING_TASK_H_ |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 7 | |
ajwong | 4f13f74 | 2017-02-09 23:52:40 | [diff] [blame] | 8 | #include <array> |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 9 | |
[email protected] | c360bae7 | 2011-11-18 06:08:02 | [diff] [blame] | 10 | #include "base/base_export.h" |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 11 | #include "base/callback.h" |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 12 | #include "base/location.h" |
Erik Chen | a9533519 | 2018-07-30 17:48:22 | [diff] [blame] | 13 | #include "base/optional.h" |
[email protected] | 8f9a3a5 | 2013-06-28 15:14:18 | [diff] [blame] | 14 | #include "base/time/time.h" |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 15 | |
| 16 | namespace base { |
| 17 | |
Alex Clarke | 1ac1f98 | 2019-03-29 08:48:37 | [diff] [blame] | 18 | enum class Nestable : uint8_t { |
Hajime Hoshi | 64853ef | 2017-10-11 12:56:07 | [diff] [blame] | 19 | kNonNestable, |
| 20 | kNestable, |
| 21 | }; |
| 22 | |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 23 | // Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue |
| 24 | // for use by classes that queue and execute tasks. |
Brett Wilson | b57e3dd | 2017-09-08 00:47:49 | [diff] [blame] | 25 | struct BASE_EXPORT PendingTask { |
Jesse McKenna | 9cf1137 | 2018-11-01 19:38:38 | [diff] [blame] | 26 | PendingTask(); |
Brett Wilson | 8e88b31 | 2017-09-12 05:22:16 | [diff] [blame] | 27 | PendingTask(const Location& posted_from, |
tzik | 739ffe3 | 2016-10-14 14:34:58 | [diff] [blame] | 28 | OnceClosure task, |
Hajime Hoshi | 64853ef | 2017-10-11 12:56:07 | [diff] [blame] | 29 | TimeTicks delayed_run_time = TimeTicks(), |
| 30 | Nestable nestable = Nestable::kNestable); |
tzik | b6769d5 | 2016-07-07 20:20:06 | [diff] [blame] | 31 | PendingTask(PendingTask&& other); |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 32 | ~PendingTask(); |
| 33 | |
tzik | b6769d5 | 2016-07-07 20:20:06 | [diff] [blame] | 34 | PendingTask& operator=(PendingTask&& other); |
| 35 | |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 36 | // Used to support sorting. |
| 37 | bool operator<(const PendingTask& other) const; |
| 38 | |
| 39 | // The task to run. |
tzik | 739ffe3 | 2016-10-14 14:34:58 | [diff] [blame] | 40 | OnceClosure task; |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 41 | |
| 42 | // The site this PendingTask was posted from. |
Brett Wilson | 8e88b31 | 2017-09-12 05:22:16 | [diff] [blame] | 43 | Location posted_from; |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 44 | |
Francois Doray | 118223f4 | 2019-12-04 17:00:28 | [diff] [blame] | 45 | // The time when the task should be run. This is null for an immediate task. |
Brett Wilson | b57e3dd | 2017-09-08 00:47:49 | [diff] [blame] | 46 | base::TimeTicks delayed_run_time; |
| 47 | |
Etienne Pierre-doray | 2d07903 | 2019-02-07 15:18:23 | [diff] [blame] | 48 | // The time at which the task was queued. For SequenceManager tasks and |
Gabriel Charette | 499ef40d | 2020-11-25 18:03:59 | [diff] [blame] | 49 | // ThreadPool non-delayed tasks, this happens at post time. For ThreadPool |
| 50 | // delayed tasks, this happens some time after the task's delay has expired. |
| 51 | // For deferred non-nestable tasks, this is reset when the nested loop exits |
| 52 | // and the deferred tasks are pushed back at the front of the queue. This is |
| 53 | // not set for SequenceManager tasks if SetAddQueueTimeToTasks(true) wasn't |
| 54 | // called. This defaults to a null TimeTicks if the task hasn't been inserted |
| 55 | // in a sequence yet. |
Karolina Soltys | fe88c9e | 2018-11-06 15:27:01 | [diff] [blame] | 56 | TimeTicks queue_time; |
Erik Chen | a9533519 | 2018-07-30 17:48:22 | [diff] [blame] | 57 | |
Alan Cutter | 9b0e1ab | 2019-03-21 04:22:16 | [diff] [blame] | 58 | // Chain of symbols of the parent tasks which led to this one being posted. |
| 59 | static constexpr size_t kTaskBacktraceLength = 4; |
| 60 | std::array<const void*, kTaskBacktraceLength> task_backtrace = {}; |
ajwong | 4f13f74 | 2017-02-09 23:52:40 | [diff] [blame] | 61 | |
Chris Hamilton | 60dcc26b | 2019-04-24 16:59:51 | [diff] [blame] | 62 | // The context of the IPC message that was being handled when this task was |
Chris Hamilton | 88808531 | 2019-05-30 00:53:30 | [diff] [blame] | 63 | // posted. This is a hash of the IPC message name that is set within the scope |
| 64 | // of an IPC handler and when symbolized uniquely identifies the message being |
Harkiran Bolaria | 875dd0d | 2020-09-15 18:10:46 | [diff] [blame] | 65 | // processed. This property is not propagated from one PendingTask to the |
Chris Hamilton | 60dcc26b | 2019-04-24 16:59:51 | [diff] [blame] | 66 | // next. For example, if pending task A was posted while handling an IPC, |
| 67 | // and pending task B was posted from within pending task A, then pending task |
Harkiran Bolaria | 875dd0d | 2020-09-15 18:10:46 | [diff] [blame] | 68 | // B will not inherit the |ipc_hash| of pending task A. |
Chris Hamilton | 88808531 | 2019-05-30 00:53:30 | [diff] [blame] | 69 | uint32_t ipc_hash = 0; |
Harkiran Bolaria | 875dd0d | 2020-09-15 18:10:46 | [diff] [blame] | 70 | const char* ipc_interface_name = nullptr; |
Chris Hamilton | 60dcc26b | 2019-04-24 16:59:51 | [diff] [blame] | 71 | |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 72 | // Secondary sort key for run time. |
Gabriel Charette | ae4f9ce | 2018-04-05 19:00:01 | [diff] [blame] | 73 | int sequence_num = 0; |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 74 | |
Alex Clarke | 1ac1f98 | 2019-03-29 08:48:37 | [diff] [blame] | 75 | bool task_backtrace_overflow = false; |
| 76 | |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 77 | // OK to dispatch from a nested loop. |
Hajime Hoshi | 64853ef | 2017-10-11 12:56:07 | [diff] [blame] | 78 | Nestable nestable; |
cpu | ee890795 | 2014-08-28 23:25:37 | [diff] [blame] | 79 | |
| 80 | // Needs high resolution timers. |
Gabriel Charette | ae4f9ce | 2018-04-05 19:00:01 | [diff] [blame] | 81 | bool is_high_res = false; |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 82 | }; |
| 83 | |
[email protected] | dd1f9fe | 2011-11-15 23:36:30 | [diff] [blame] | 84 | } // namespace base |
| 85 | |
danakj | 0a44860 | 2015-03-10 00:31:16 | [diff] [blame] | 86 | #endif // BASE_PENDING_TASK_H_ |