Index: components/scheduler/child/task_queue_impl.h |
diff --git a/components/scheduler/child/task_queue_impl.h b/components/scheduler/child/task_queue_impl.h |
index 1e05e5ab0069ef0dbc0198ca11b332e5ec8beee7..99c565b43e234f5885221bc49aae6da8cf64037b 100644 |
--- a/components/scheduler/child/task_queue_impl.h |
+++ b/components/scheduler/child/task_queue_impl.h |
@@ -27,6 +27,39 @@ class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { |
const char* disabled_by_default_tracing_category, |
const char* disabled_by_default_verbose_tracing_category); |
+ class SCHEDULER_EXPORT Task : public base::PendingTask { |
+ public: |
+ Task(); |
+ Task(const tracked_objects::Location& posted_from, |
+ const base::Closure& task, |
+ int sequence_number, |
+ bool nestable); |
+ |
+ int enqueue_order() const { |
+#ifndef NDEBUG |
+ DCHECK(enqueue_order_set_); |
+#endif |
+ return enqueue_order_; |
+ } |
+ |
+ void set_enqueue_order(int enqueue_order) { |
+#ifndef NDEBUG |
+ DCHECK(!enqueue_order_set_); |
+ enqueue_order_set_ = true; |
+#endif |
+ enqueue_order_ = enqueue_order; |
+ } |
+ |
+ private: |
+#ifndef NDEBUG |
+ bool enqueue_order_set_; |
+#endif |
+ // Similar to sequence number, but the |enqueue_order| is set by |
+ // EnqueueTasksLocked and is not initially defined for delayed tasks until |
+ // they are enqueued on the |incoming_queue_|. |
+ int enqueue_order_; |
+ }; |
+ |
// TaskQueue implementation. |
bool RunsTasksOnCurrentThread() const override; |
bool PostDelayedTask(const tracked_objects::Location& from_here, |
@@ -50,12 +83,12 @@ class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { |
void UpdateWorkQueue(LazyNow* lazy_now, |
bool should_trigger_wakeup, |
- const base::PendingTask* previous_task); |
- base::PendingTask TakeTaskFromWorkQueue(); |
+ const Task* previous_task); |
+ Task TakeTaskFromWorkQueue(); |
void WillDeleteTaskQueueManager(); |
- base::TaskQueue& work_queue() { return work_queue_; } |
+ std::queue<Task>& work_queue() { return work_queue_; } |
WakeupPolicy wakeup_policy() const { |
DCHECK(main_thread_checker_.CalledOnValidThread()); |
@@ -70,16 +103,16 @@ class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { |
void set_task_queue_set_index(size_t set_index) { set_index_ = set_index; } |
- // If the work queue isn't empty, |age| gets set to the sequence number of the |
- // front task and the dunctio returns true. Otherwise the function returns |
- // false. |
- bool GetWorkQueueFrontTaskAge(int* age) const; |
+ // If the work queue isn't empty, |enqueue_order| gets set to the enqueue |
+ // order of the front task and the function returns true. Otherwise the |
+ // function returns false. |
+ bool GetWorkQueueFrontTaskEnqueueOrder(int* enqueue_order) const; |
bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; } |
bool GetShouldNotifyObservers() const { return should_notify_observers_; } |
// Test support functions. These should not be used in production code. |
- void PushTaskOntoWorkQueueForTest(const base::PendingTask& task); |
+ void PushTaskOntoWorkQueueForTest(const Task& task); |
void PopTaskFromWorkQueueForTest(); |
size_t WorkQueueSizeForTest() const { return work_queue_.size(); } |
@@ -126,20 +159,23 @@ class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { |
void ScheduleDelayedWorkLocked(LazyNow* lazy_now); |
void PumpQueueLocked(); |
- bool TaskIsOlderThanQueuedTasks(const base::PendingTask* task); |
+ bool TaskIsOlderThanQueuedTasks(const Task* task); |
bool ShouldAutoPumpQueueLocked(bool should_trigger_wakeup, |
- const base::PendingTask* previous_task); |
+ const Task* previous_task); |
+ |
+ enum class EnqueueOrderPolicy { SET_ENQUEUE_ORDER, DONT_SET_ENQUEUE_ORDER }; |
- // Push the task onto the |incoming_queue_| and allocate a sequence number |
- // for it. |
- void EnqueueTaskLocked(const base::PendingTask& pending_task); |
+ // Push the task onto the |incoming_queue_| and maybe allocate an |
+ // enqueue_order for it based on |enqueue_order_policy|. |
+ void EnqueueTaskLocked(const Task& pending_task, |
+ EnqueueOrderPolicy enqueue_order_policy); |
void TraceQueueSize(bool is_locked) const; |
- static void QueueAsValueInto(const base::TaskQueue& queue, |
+ static void QueueAsValueInto(const std::queue<Task>& queue, |
base::trace_event::TracedValue* state); |
- static void QueueAsValueInto(const base::DelayedTaskQueue& queue, |
+ static void QueueAsValueInto(const std::priority_queue<Task>& queue, |
base::trace_event::TracedValue* state); |
- static void TaskAsValueInto(const base::PendingTask& task, |
+ static void TaskAsValueInto(const Task& task, |
base::trace_event::TracedValue* state); |
// This lock protects all members in the contigious block below. |
@@ -147,13 +183,9 @@ class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { |
mutable base::Lock lock_; |
base::PlatformThreadId thread_id_; |
TaskQueueManager* task_queue_manager_; |
- base::TaskQueue incoming_queue_; |
+ std::queue<Task> incoming_queue_; |
PumpPolicy pump_policy_; |
- // Queue-local task sequence number for maintaining the order of delayed |
- // tasks which are posted for the exact same time. Note that this will be |
- // replaced by the global sequence number when the delay has elapsed. |
- int delayed_task_sequence_number_; |
- base::DelayedTaskQueue delayed_task_queue_; |
+ std::priority_queue<Task> delayed_task_queue_; |
std::set<base::TimeTicks> in_flight_kick_delayed_tasks_; |
const char* name_; |
@@ -161,7 +193,7 @@ class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { |
const char* disabled_by_default_verbose_tracing_category_; |
base::ThreadChecker main_thread_checker_; |
- base::TaskQueue work_queue_; |
+ std::queue<Task> work_queue_; |
WakeupPolicy wakeup_policy_; |
size_t set_index_; |
bool should_monitor_quiescence_; |