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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 // Returns true if there no tasks in either the work or incoming task queue | 74 // Returns true if there no tasks in either the work or incoming task queue |
75 // identified by |queue_index|. Note that this function involves taking a | 75 // identified by |queue_index|. Note that this function involves taking a |
76 // lock, so calling it has some overhead. | 76 // lock, so calling it has some overhead. |
77 bool IsQueueEmpty(size_t queue_index) const; | 77 bool IsQueueEmpty(size_t queue_index) const; |
78 | 78 |
79 // Set the name |queue_index| for tracing purposes. |name| must be a pointer | 79 // Set the name |queue_index| for tracing purposes. |name| must be a pointer |
80 // to a static string. | 80 // to a static string. |
81 void SetQueueName(size_t queue_index, const char* name); | 81 void SetQueueName(size_t queue_index, const char* name); |
82 | 82 |
| 83 // Set the number of tasks executed in a single invocation of the task queue |
| 84 // manager. Increasing the batch size can reduce the overhead of yielding |
| 85 // back to the main message loop -- at the cost of potentially delaying other |
| 86 // tasks posted to the main loop. The batch size is 1 by default. |
| 87 void SetWorkBatchSize(int work_batch_size); |
| 88 |
83 private: | 89 private: |
84 friend class internal::TaskQueue; | 90 friend class internal::TaskQueue; |
85 | 91 |
86 // Called by the task queue to register a new pending task and allocate a | 92 // Called by the task queue to register a new pending task and allocate a |
87 // sequence number for it. | 93 // sequence number for it. |
88 void DidQueueTask(base::PendingTask* pending_task); | 94 void DidQueueTask(base::PendingTask* pending_task); |
89 | 95 |
90 // Post a task to call DoWork() on the main task runner. Only one pending | 96 // Post a task to call DoWork() on the main task runner. Only one pending |
91 // DoWork is allowed from the main thread, to prevent an explosion of pending | 97 // DoWork is allowed from the main thread, to prevent an explosion of pending |
92 // DoWorks. | 98 // DoWorks. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 base::ThreadChecker main_thread_checker_; | 134 base::ThreadChecker main_thread_checker_; |
129 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 135 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
130 TaskQueueSelector* selector_; | 136 TaskQueueSelector* selector_; |
131 | 137 |
132 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_; | 138 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_; |
133 | 139 |
134 // The pending_dowork_count_ is only tracked on the main thread since that's | 140 // The pending_dowork_count_ is only tracked on the main thread since that's |
135 // where re-entrant problems happen. | 141 // where re-entrant problems happen. |
136 int pending_dowork_count_; | 142 int pending_dowork_count_; |
137 | 143 |
| 144 int work_batch_size_; |
| 145 |
138 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 146 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
139 | 147 |
140 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 148 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
141 }; | 149 }; |
142 | 150 |
143 } // namespace content | 151 } // namespace content |
144 | 152 |
145 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ | 153 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ |
OLD | NEW |