Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_IMPL_H_ |
| 6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_IMPL_H_ | 6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_IMPL_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/pending_task.h" | 10 #include "base/pending_task.h" |
| 11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "base/trace_event/trace_event_argument.h" | 13 #include "base/trace_event/trace_event_argument.h" |
| 14 #include "components/scheduler/child/lazy_now.h" | 14 #include "components/scheduler/child/lazy_now.h" |
| 15 #include "components/scheduler/child/task_queue.h" | 15 #include "components/scheduler/child/task_queue.h" |
| 16 #include "components/scheduler/scheduler_export.h" | 16 #include "components/scheduler/scheduler_export.h" |
| 17 | 17 |
| 18 namespace scheduler { | 18 namespace scheduler { |
| 19 class TaskQueueManager; | 19 class TaskQueueManager; |
| 20 | 20 |
| 21 namespace internal { | 21 namespace internal { |
| 22 | 22 |
| 23 struct SchedulerTask : public base::PendingTask { | |
|
Sami
2015/08/05 11:27:34
Sorry to go all bikeshed on this but I think TQM i
alex clarke (OOO till 29th)
2015/08/05 14:32:43
Done.
| |
| 24 SchedulerTask(); | |
| 25 SchedulerTask(const tracked_objects::Location& posted_from, | |
| 26 const base::Closure& task, | |
| 27 bool nestable); | |
| 28 | |
| 29 // Similar to sequence number, but the task age is not defined for delayed | |
| 30 // tasks until enqueued on the |incomming_queue_|. | |
|
Sami
2015/08/05 11:27:34
typo: incoming
alex clarke (OOO till 29th)
2015/08/05 14:32:43
Done.
| |
| 31 int age; | |
| 32 }; | |
| 33 | |
| 23 class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { | 34 class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { |
| 24 public: | 35 public: |
| 25 TaskQueueImpl(TaskQueueManager* task_queue_manager, | 36 TaskQueueImpl(TaskQueueManager* task_queue_manager, |
| 26 const Spec& spec, | 37 const Spec& spec, |
| 27 const char* disabled_by_default_tracing_category, | 38 const char* disabled_by_default_tracing_category, |
| 28 const char* disabled_by_default_verbose_tracing_category); | 39 const char* disabled_by_default_verbose_tracing_category); |
| 29 | 40 |
| 30 // TaskQueue implementation. | 41 // TaskQueue implementation. |
| 31 bool RunsTasksOnCurrentThread() const override; | 42 bool RunsTasksOnCurrentThread() const override; |
| 32 bool PostDelayedTask(const tracked_objects::Location& from_here, | 43 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 43 QueueState GetQueueState() const override; | 54 QueueState GetQueueState() const override; |
| 44 void SetQueuePriority(QueuePriority priority) override; | 55 void SetQueuePriority(QueuePriority priority) override; |
| 45 void PumpQueue() override; | 56 void PumpQueue() override; |
| 46 void SetPumpPolicy(PumpPolicy pump_policy) override; | 57 void SetPumpPolicy(PumpPolicy pump_policy) override; |
| 47 | 58 |
| 48 bool NextPendingDelayedTaskRunTime( | 59 bool NextPendingDelayedTaskRunTime( |
| 49 base::TimeTicks* next_pending_delayed_task); | 60 base::TimeTicks* next_pending_delayed_task); |
| 50 | 61 |
| 51 void UpdateWorkQueue(LazyNow* lazy_now, | 62 void UpdateWorkQueue(LazyNow* lazy_now, |
| 52 bool should_trigger_wakeup, | 63 bool should_trigger_wakeup, |
| 53 const base::PendingTask* previous_task); | 64 const SchedulerTask* previous_task); |
| 54 base::PendingTask TakeTaskFromWorkQueue(); | 65 SchedulerTask TakeTaskFromWorkQueue(); |
| 55 | 66 |
| 56 void WillDeleteTaskQueueManager(); | 67 void WillDeleteTaskQueueManager(); |
| 57 | 68 |
| 58 base::TaskQueue& work_queue() { return work_queue_; } | 69 std::queue<SchedulerTask>& work_queue() { return work_queue_; } |
| 59 | 70 |
| 60 WakeupPolicy wakeup_policy() const { | 71 WakeupPolicy wakeup_policy() const { |
| 61 DCHECK(main_thread_checker_.CalledOnValidThread()); | 72 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 62 return wakeup_policy_; | 73 return wakeup_policy_; |
| 63 } | 74 } |
| 64 | 75 |
| 65 const char* GetName() const override; | 76 const char* GetName() const override; |
| 66 | 77 |
| 67 void AsValueInto(base::trace_event::TracedValue* state) const; | 78 void AsValueInto(base::trace_event::TracedValue* state) const; |
| 68 | 79 |
| 69 size_t get_task_queue_set_index() const { return set_index_; } | 80 size_t get_task_queue_set_index() const { return set_index_; } |
| 70 | 81 |
| 71 void set_task_queue_set_index(size_t set_index) { set_index_ = set_index; } | 82 void set_task_queue_set_index(size_t set_index) { set_index_ = set_index; } |
| 72 | 83 |
| 73 // If the work queue isn't empty, |age| gets set to the sequence number of the | 84 // If the work queue isn't empty, |age| gets set to the sequence number of the |
| 74 // front task and the dunctio returns true. Otherwise the function returns | 85 // front task and the dunctio returns true. Otherwise the function returns |
| 75 // false. | 86 // false. |
| 76 bool GetWorkQueueFrontTaskAge(int* age) const; | 87 bool GetWorkQueueFrontTaskAge(int* age) const; |
| 77 | 88 |
| 78 bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; } | 89 bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; } |
| 79 bool GetShouldNotifyObservers() const { return should_notify_observers_; } | 90 bool GetShouldNotifyObservers() const { return should_notify_observers_; } |
| 80 | 91 |
| 81 // Test support functions. These should not be used in production code. | 92 // Test support functions. These should not be used in production code. |
| 82 void PushTaskOntoWorkQueueForTest(const base::PendingTask& task); | 93 void PushTaskOntoWorkQueueForTest(const SchedulerTask& task); |
| 83 void PopTaskFromWorkQueueForTest(); | 94 void PopTaskFromWorkQueueForTest(); |
| 84 size_t WorkQueueSizeForTest() const { return work_queue_.size(); } | 95 size_t WorkQueueSizeForTest() const { return work_queue_.size(); } |
| 85 | 96 |
| 86 // Can be called on any thread. | 97 // Can be called on any thread. |
| 87 static const char* PumpPolicyToString(TaskQueue::PumpPolicy pump_policy); | 98 static const char* PumpPolicyToString(TaskQueue::PumpPolicy pump_policy); |
| 88 | 99 |
| 89 // Can be called on any thread. | 100 // Can be called on any thread. |
| 90 static const char* WakeupPolicyToString( | 101 static const char* WakeupPolicyToString( |
| 91 TaskQueue::WakeupPolicy wakeup_policy); | 102 TaskQueue::WakeupPolicy wakeup_policy); |
| 92 | 103 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 119 // Enqueues any delayed tasks which should be run now on the incoming_queue_ | 130 // Enqueues any delayed tasks which should be run now on the incoming_queue_ |
| 120 // and calls ScheduleDelayedWorkLocked to ensure future tasks are scheduled. | 131 // and calls ScheduleDelayedWorkLocked to ensure future tasks are scheduled. |
| 121 // Must be called with |lock_| locked. | 132 // Must be called with |lock_| locked. |
| 122 void MoveReadyDelayedTasksToIncomingQueueLocked(LazyNow* lazy_now); | 133 void MoveReadyDelayedTasksToIncomingQueueLocked(LazyNow* lazy_now); |
| 123 | 134 |
| 124 // Posts MoveReadyDelayedTasksToIncomingQueue if there isn't already a task | 135 // Posts MoveReadyDelayedTasksToIncomingQueue if there isn't already a task |
| 125 // posted on the underlying runloop for the next task's scheduled run time. | 136 // posted on the underlying runloop for the next task's scheduled run time. |
| 126 void ScheduleDelayedWorkLocked(LazyNow* lazy_now); | 137 void ScheduleDelayedWorkLocked(LazyNow* lazy_now); |
| 127 | 138 |
| 128 void PumpQueueLocked(); | 139 void PumpQueueLocked(); |
| 129 bool TaskIsOlderThanQueuedTasks(const base::PendingTask* task); | 140 bool TaskIsOlderThanQueuedTasks(const SchedulerTask* task); |
| 130 bool ShouldAutoPumpQueueLocked(bool should_trigger_wakeup, | 141 bool ShouldAutoPumpQueueLocked(bool should_trigger_wakeup, |
| 131 const base::PendingTask* previous_task); | 142 const SchedulerTask* previous_task); |
| 132 | 143 |
| 133 // Push the task onto the |incoming_queue_| and allocate a sequence number | 144 // Push the task onto the |incoming_queue_| and allocate a sequence number |
| 134 // for it. | 145 // for it. |
| 135 void EnqueueTaskLocked(const base::PendingTask& pending_task); | 146 void EnqueueTaskLocked(const SchedulerTask& pending_task); |
| 136 | 147 |
| 137 void TraceQueueSize(bool is_locked) const; | 148 void TraceQueueSize(bool is_locked) const; |
| 138 static void QueueAsValueInto(const base::TaskQueue& queue, | 149 static void QueueAsValueInto(const std::queue<SchedulerTask>& queue, |
| 139 base::trace_event::TracedValue* state); | 150 base::trace_event::TracedValue* state); |
| 140 static void QueueAsValueInto(const base::DelayedTaskQueue& queue, | 151 static void QueueAsValueInto(const std::priority_queue<SchedulerTask>& queue, |
| 141 base::trace_event::TracedValue* state); | 152 base::trace_event::TracedValue* state); |
| 142 static void TaskAsValueInto(const base::PendingTask& task, | 153 static void TaskAsValueInto(const SchedulerTask& task, |
| 143 base::trace_event::TracedValue* state); | 154 base::trace_event::TracedValue* state); |
| 144 | 155 |
| 145 // This lock protects all members in the contigious block below. | 156 // This lock protects all members in the contigious block below. |
| 146 // TODO(alexclarke): Group all the members protected by the lock into a struct | 157 // TODO(alexclarke): Group all the members protected by the lock into a struct |
| 147 mutable base::Lock lock_; | 158 mutable base::Lock lock_; |
| 148 base::PlatformThreadId thread_id_; | 159 base::PlatformThreadId thread_id_; |
| 149 TaskQueueManager* task_queue_manager_; | 160 TaskQueueManager* task_queue_manager_; |
| 150 base::TaskQueue incoming_queue_; | 161 std::queue<SchedulerTask> incoming_queue_; |
| 151 PumpPolicy pump_policy_; | 162 PumpPolicy pump_policy_; |
| 152 // Queue-local task sequence number for maintaining the order of delayed | 163 std::priority_queue<SchedulerTask> delayed_task_queue_; |
| 153 // tasks which are posted for the exact same time. Note that this will be | |
| 154 // replaced by the global sequence number when the delay has elapsed. | |
| 155 int delayed_task_sequence_number_; | |
| 156 base::DelayedTaskQueue delayed_task_queue_; | |
| 157 std::set<base::TimeTicks> in_flight_kick_delayed_tasks_; | 164 std::set<base::TimeTicks> in_flight_kick_delayed_tasks_; |
| 158 | 165 |
| 159 const char* name_; | 166 const char* name_; |
| 160 const char* disabled_by_default_tracing_category_; | 167 const char* disabled_by_default_tracing_category_; |
| 161 const char* disabled_by_default_verbose_tracing_category_; | 168 const char* disabled_by_default_verbose_tracing_category_; |
| 162 | 169 |
| 163 base::ThreadChecker main_thread_checker_; | 170 base::ThreadChecker main_thread_checker_; |
| 164 base::TaskQueue work_queue_; | 171 std::queue<SchedulerTask> work_queue_; |
| 165 WakeupPolicy wakeup_policy_; | 172 WakeupPolicy wakeup_policy_; |
| 166 size_t set_index_; | 173 size_t set_index_; |
| 167 bool should_monitor_quiescence_; | 174 bool should_monitor_quiescence_; |
| 168 bool should_notify_observers_; | 175 bool should_notify_observers_; |
| 169 | 176 |
| 170 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); | 177 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); |
| 171 }; | 178 }; |
| 172 | 179 |
| 173 } // namespace internal | 180 } // namespace internal |
| 174 } // namespace scheduler | 181 } // namespace scheduler |
| 175 | 182 |
| 176 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_IMPL_H_ | 183 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_IMPL_H_ |
| OLD | NEW |