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 5 #ifndef BASE_PENDING_TASK_H_ 6 #define BASE_PENDING_TASK_H_ 7 8 #include <array> 9 #include <queue> 10 11 #include "base/base_export.h" 12 #include "base/callback.h" 13 #include "base/location.h" 14 #include "base/time/time.h" 15 #include "base/tracking_info.h" 16 17 namespace base { 18 19 // Contains data about a pending task. Stored in TaskQueue and DelayedTaskQueue 20 // for use by classes that queue and execute tasks. 21 struct BASE_EXPORT PendingTask : public TrackingInfo { 22 PendingTask(const tracked_objects::Location& posted_from, OnceClosure task); 23 PendingTask(const tracked_objects::Location& posted_from, 24 OnceClosure task, 25 TimeTicks delayed_run_time, 26 bool nestable); 27 PendingTask(PendingTask&& other); 28 ~PendingTask(); 29 30 PendingTask& operator=(PendingTask&& other); 31 32 // Used to support sorting. 33 bool operator<(const PendingTask& other) const; 34 35 // The task to run. 36 OnceClosure task; 37 38 // The site this PendingTask was posted from. 39 tracked_objects::Location posted_from; 40 41 // Task backtrace. 42 std::array<const void*, 4> task_backtrace; 43 44 // Secondary sort key for run time. 45 int sequence_num; 46 47 // OK to dispatch from a nested loop. 48 bool nestable; 49 50 // Needs high resolution timers. 51 bool is_high_res; 52 }; 53 54 using TaskQueue = std::queue<PendingTask>; 55 56 // PendingTasks are sorted by their |delayed_run_time| property. 57 using DelayedTaskQueue = std::priority_queue<base::PendingTask>; 58 59 } // namespace base 60 61 #endif // BASE_PENDING_TASK_H_ 62