jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [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 | 0393da3 | 2015-03-10 09:31:16 +0900 | [diff] [blame] | 5 | #ifndef BASE_PENDING_TASK_H_ |
| 6 | #define BASE_PENDING_TASK_H_ |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 7 | |
ajwong | 8d51d07 | 2017-02-10 08:52:40 +0900 | [diff] [blame] | 8 | #include <array> |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 9 | |
rsleevi@chromium.org | 3f19acb | 2011-11-18 15:08:02 +0900 | [diff] [blame] | 10 | #include "base/base_export.h" |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 11 | #include "base/callback.h" |
Brett Wilson | 94ac4d1 | 2017-08-15 04:54:38 +0900 | [diff] [blame] | 12 | #include "base/containers/queue.h" |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 13 | #include "base/location.h" |
avi@chromium.org | b45ec93 | 2013-06-29 00:14:18 +0900 | [diff] [blame] | 14 | #include "base/time/time.h" |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 15 | |
| 16 | namespace base { |
| 17 | |
Hajime Hoshi | 67c2dbe | 2017-10-11 21:56:07 +0900 | [diff] [blame] | 18 | enum class Nestable { |
| 19 | kNonNestable, |
| 20 | kNestable, |
| 21 | }; |
| 22 | |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [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 | c7c59cb | 2017-09-08 09:47:49 +0900 | [diff] [blame] | 25 | struct BASE_EXPORT PendingTask { |
Brett Wilson | 89388db | 2017-09-12 14:22:16 +0900 | [diff] [blame] | 26 | PendingTask(const Location& posted_from, |
tzik | e82b7e8 | 2016-10-14 23:34:58 +0900 | [diff] [blame] | 27 | OnceClosure task, |
Hajime Hoshi | 67c2dbe | 2017-10-11 21:56:07 +0900 | [diff] [blame] | 28 | TimeTicks delayed_run_time = TimeTicks(), |
| 29 | Nestable nestable = Nestable::kNestable); |
tzik | c74f6fe | 2016-07-08 05:20:06 +0900 | [diff] [blame] | 30 | PendingTask(PendingTask&& other); |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 31 | ~PendingTask(); |
| 32 | |
tzik | c74f6fe | 2016-07-08 05:20:06 +0900 | [diff] [blame] | 33 | PendingTask& operator=(PendingTask&& other); |
| 34 | |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 35 | // Used to support sorting. |
| 36 | bool operator<(const PendingTask& other) const; |
| 37 | |
| 38 | // The task to run. |
tzik | e82b7e8 | 2016-10-14 23:34:58 +0900 | [diff] [blame] | 39 | OnceClosure task; |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 40 | |
| 41 | // The site this PendingTask was posted from. |
Brett Wilson | 89388db | 2017-09-12 14:22:16 +0900 | [diff] [blame] | 42 | Location posted_from; |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 43 | |
Brett Wilson | c7c59cb | 2017-09-08 09:47:49 +0900 | [diff] [blame] | 44 | // The time when the task should be run. |
| 45 | base::TimeTicks delayed_run_time; |
| 46 | |
ajwong | 8d51d07 | 2017-02-10 08:52:40 +0900 | [diff] [blame] | 47 | // Task backtrace. |
| 48 | std::array<const void*, 4> task_backtrace; |
| 49 | |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 50 | // Secondary sort key for run time. |
| 51 | int sequence_num; |
| 52 | |
| 53 | // OK to dispatch from a nested loop. |
Hajime Hoshi | 67c2dbe | 2017-10-11 21:56:07 +0900 | [diff] [blame] | 54 | Nestable nestable; |
cpu | 410a98e | 2014-08-29 08:25:37 +0900 | [diff] [blame] | 55 | |
| 56 | // Needs high resolution timers. |
| 57 | bool is_high_res; |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 58 | }; |
| 59 | |
Brett Wilson | 94ac4d1 | 2017-08-15 04:54:38 +0900 | [diff] [blame] | 60 | using TaskQueue = base::queue<PendingTask>; |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 61 | |
jhawkins@chromium.org | 303de23 | 2011-11-18 08:26:53 +0900 | [diff] [blame] | 62 | // PendingTasks are sorted by their |delayed_run_time| property. |
danakj | b82557d | 2016-06-16 05:47:47 +0900 | [diff] [blame] | 63 | using DelayedTaskQueue = std::priority_queue<base::PendingTask>; |
jhawkins@chromium.org | 303de23 | 2011-11-18 08:26:53 +0900 | [diff] [blame] | 64 | |
jhawkins@chromium.org | 2af12f2 | 2011-11-16 08:36:30 +0900 | [diff] [blame] | 65 | } // namespace base |
| 66 | |
danakj | 0393da3 | 2015-03-10 09:31:16 +0900 | [diff] [blame] | 67 | #endif // BASE_PENDING_TASK_H_ |