OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_MANAGER_H_ | 5 #ifndef CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
7 | 7 |
8 #include "base/atomic_sequence_num.h" | 8 #include "base/atomic_sequence_num.h" |
9 #include "base/debug/task_annotator.h" | 9 #include "base/debug/task_annotator.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 // When a task is appended into an empty incoming queue, the task manager | 41 // When a task is appended into an empty incoming queue, the task manager |
42 // work function (DoWork) is scheduled to run on the main task runner. | 42 // work function (DoWork) is scheduled to run on the main task runner. |
43 // | 43 // |
44 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from | 44 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from |
45 // the incoming task queue (if any) are moved here. The work queues are | 45 // the incoming task queue (if any) are moved here. The work queues are |
46 // registered with the selector as input to the scheduling decision. | 46 // registered with the selector as input to the scheduling decision. |
47 // | 47 // |
48 class CONTENT_EXPORT TaskQueueManager { | 48 class CONTENT_EXPORT TaskQueueManager { |
49 public: | 49 public: |
50 // Keep TaskQueue::PumpPolicyToString in sync with this enum. | 50 // Keep TaskQueue::PumpPolicyToString in sync with this enum. |
51 enum PumpPolicy { | 51 enum class PumpPolicy { |
52 // Tasks posted to an incoming queue with an AUTO_PUMP_POLICY will be | 52 // Tasks posted to an incoming queue with an AUTO pump policy will be |
53 // automatically scheduled for execution or transferred to the work queue | 53 // automatically scheduled for execution or transferred to the work queue |
54 // automatically. | 54 // automatically. |
55 AUTO_PUMP_POLICY, | 55 AUTO, |
56 // Tasks posted to an incoming queue with an AUTO_PUMP_AFTER_WAKEUP_POLICY | 56 // Tasks posted to an incoming queue with an AFTER_WAKEUP pump policy |
57 // will be scheduled for execution or transferred to the work queue | 57 // will be scheduled for execution or transferred to the work queue |
58 // automatically but only after another queue has executed a task. | 58 // automatically but only after another queue has executed a task. |
59 AUTO_PUMP_AFTER_WAKEUP_POLICY, | 59 AFTER_WAKEUP, |
60 // Tasks posted to an incoming queue with a MANUAL_PUMP_POLICY will not be | 60 // Tasks posted to an incoming queue with a MANUAL will not be |
61 // automatically scheduled for execution or transferred to the work queue. | 61 // automatically scheduled for execution or transferred to the work queue. |
62 // Instead, the selector should call PumpQueue() when necessary to bring | 62 // Instead, the selector should call PumpQueue() when necessary to bring |
63 // in new tasks for execution. | 63 // in new tasks for execution. |
64 MANUAL_PUMP_POLICY | 64 MANUAL |
65 }; | 65 }; |
66 | 66 |
67 // Create a task queue manager with |task_queue_count| task queues. | 67 // Create a task queue manager with |task_queue_count| task queues. |
68 // |main_task_runner| identifies the thread on which where the tasks are | 68 // |main_task_runner| identifies the thread on which where the tasks are |
69 // eventually run. |selector| is used to choose which task queue to service. | 69 // eventually run. |selector| is used to choose which task queue to service. |
70 // It should outlive this class. | 70 // It should outlive this class. |
71 TaskQueueManager(size_t task_queue_count, | 71 TaskQueueManager(size_t task_queue_count, |
72 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 72 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
73 TaskQueueSelector* selector); | 73 TaskQueueSelector* selector); |
74 ~TaskQueueManager(); | 74 ~TaskQueueManager(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // These functions can only be called on the same thread that the task queue | 109 // These functions can only be called on the same thread that the task queue |
110 // manager executes its tasks on. | 110 // manager executes its tasks on. |
111 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 111 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
112 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); | 112 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); |
113 | 113 |
114 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); | 114 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); |
115 | 115 |
116 private: | 116 private: |
117 friend class internal::TaskQueue; | 117 friend class internal::TaskQueue; |
118 | 118 |
119 enum WorkQueueUpdateEventType { | 119 enum class WorkQueueUpdateEventType { BEFORE_WAKEUP, AFTER_WAKEUP }; |
120 BEFORE_WAKEUP_EVENT_TYPE, | |
121 AFTER_WAKEUP_EVENT_TYPE | |
122 }; | |
123 | 120 |
124 // Called by the task queue to register a new pending task and allocate a | 121 // Called by the task queue to register a new pending task and allocate a |
125 // sequence number for it. | 122 // sequence number for it. |
126 void DidQueueTask(base::PendingTask* pending_task); | 123 void DidQueueTask(base::PendingTask* pending_task); |
127 | 124 |
128 // Post a task to call DoWork() on the main task runner. Only one pending | 125 // Post a task to call DoWork() on the main task runner. Only one pending |
129 // DoWork is allowed from the main thread, to prevent an explosion of pending | 126 // DoWork is allowed from the main thread, to prevent an explosion of pending |
130 // DoWorks. | 127 // DoWorks. |
131 void MaybePostDoWorkOnMainRunner(); | 128 void MaybePostDoWorkOnMainRunner(); |
132 | 129 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 ObserverList<base::MessageLoop::TaskObserver> task_observers_; | 186 ObserverList<base::MessageLoop::TaskObserver> task_observers_; |
190 | 187 |
191 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 188 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
192 | 189 |
193 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 190 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
194 }; | 191 }; |
195 | 192 |
196 } // namespace content | 193 } // namespace content |
197 | 194 |
198 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 195 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
OLD | NEW |