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_BASE_TASK_QUEUE_MANAGER_H_ | 5 #ifndef CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ |
6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ | 6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 namespace scheduler { | 32 namespace scheduler { |
33 namespace internal { | 33 namespace internal { |
34 class TaskQueueImpl; | 34 class TaskQueueImpl; |
35 } // namespace internal | 35 } // namespace internal |
36 | 36 |
37 class LazyNow; | 37 class LazyNow; |
38 class RealTimeDomain; | 38 class RealTimeDomain; |
39 class TimeDomain; | 39 class TimeDomain; |
40 class TaskQueueManagerDelegate; | 40 class TaskQueueManagerDelegate; |
| 41 class TaskTimeTracker; |
41 | 42 |
42 // The task queue manager provides N task queues and a selector interface for | 43 // The task queue manager provides N task queues and a selector interface for |
43 // choosing which task queue to service next. Each task queue consists of two | 44 // choosing which task queue to service next. Each task queue consists of two |
44 // sub queues: | 45 // sub queues: |
45 // | 46 // |
46 // 1. Incoming task queue. Tasks that are posted get immediately appended here. | 47 // 1. Incoming task queue. Tasks that are posted get immediately appended here. |
47 // When a task is appended into an empty incoming queue, the task manager | 48 // When a task is appended into an empty incoming queue, the task manager |
48 // work function (DoWork) is scheduled to run on the main task runner. | 49 // work function (DoWork) is scheduled to run on the main task runner. |
49 // | 50 // |
50 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from | 51 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from |
51 // the incoming task queue (if any) are moved here. The work queues are | 52 // the incoming task queue (if any) are moved here. The work queues are |
52 // registered with the selector as input to the scheduling decision. | 53 // registered with the selector as input to the scheduling decision. |
53 // | 54 // |
54 class SCHEDULER_EXPORT TaskQueueManager | 55 class SCHEDULER_EXPORT TaskQueueManager |
55 : public internal::TaskQueueSelector::Observer { | 56 : public internal::TaskQueueSelector::Observer { |
56 public: | 57 public: |
57 // Create a task queue manager where |delegate| identifies the thread | 58 // Create a task queue manager where |delegate| identifies the thread |
58 // on which where the tasks are eventually run. Category strings must have | 59 // on which where the tasks are eventually run. Category strings must have |
59 // application lifetime (statics or literals). They may not include " chars. | 60 // application lifetime (statics or literals). They may not include " chars. |
60 TaskQueueManager(scoped_refptr<TaskQueueManagerDelegate> delegate, | 61 TaskQueueManager(scoped_refptr<TaskQueueManagerDelegate> delegate, |
61 const char* tracing_category, | 62 const char* tracing_category, |
62 const char* disabled_by_default_tracing_category, | 63 const char* disabled_by_default_tracing_category, |
63 const char* disabled_by_default_verbose_tracing_category); | 64 const char* disabled_by_default_verbose_tracing_category, |
| 65 TaskTimeTracker* task_time_tracker); |
64 ~TaskQueueManager() override; | 66 ~TaskQueueManager() override; |
65 | 67 |
66 // Requests that a task to process work is posted on the main task runner. | 68 // Requests that a task to process work is posted on the main task runner. |
67 // These tasks are de-duplicated in two buckets: main-thread and all other | 69 // These tasks are de-duplicated in two buckets: main-thread and all other |
68 // threads. This distinction is done to reduce the overehead from locks, we | 70 // threads. This distinction is done to reduce the overehead from locks, we |
69 // assume the main-thread path will be hot. | 71 // assume the main-thread path will be hot. |
70 void MaybeScheduleImmediateWork(const tracked_objects::Location& from_here); | 72 void MaybeScheduleImmediateWork(const tracked_objects::Location& from_here); |
71 | 73 |
72 // Requests that a delayed task to process work is posted on the main task | 74 // Requests that a delayed task to process work is posted on the main task |
73 // runner. These delayed tasks are de-duplicated. Must be called on the thread | 75 // runner. These delayed tasks are de-duplicated. Must be called on the thread |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 234 |
233 // Protects |other_thread_pending_wakeups_|. | 235 // Protects |other_thread_pending_wakeups_|. |
234 mutable base::Lock other_thread_lock_; | 236 mutable base::Lock other_thread_lock_; |
235 std::set<base::TimeTicks> other_thread_pending_wakeups_; | 237 std::set<base::TimeTicks> other_thread_pending_wakeups_; |
236 | 238 |
237 int work_batch_size_; | 239 int work_batch_size_; |
238 size_t task_count_; | 240 size_t task_count_; |
239 | 241 |
240 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_; | 242 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_; |
241 | 243 |
| 244 TaskTimeTracker* task_time_tracker_; // NOT OWNED |
| 245 std::unique_ptr<base::TickClock> timer_; |
| 246 |
242 const char* tracing_category_; | 247 const char* tracing_category_; |
243 const char* disabled_by_default_tracing_category_; | 248 const char* disabled_by_default_tracing_category_; |
244 const char* disabled_by_default_verbose_tracing_category_; | 249 const char* disabled_by_default_verbose_tracing_category_; |
245 | 250 |
246 internal::TaskQueueImpl* currently_executing_task_queue_; // NOT OWNED | 251 internal::TaskQueueImpl* currently_executing_task_queue_; // NOT OWNED |
247 | 252 |
248 Observer* observer_; // NOT OWNED | 253 Observer* observer_; // NOT OWNED |
249 scoped_refptr<DeletionSentinel> deletion_sentinel_; | 254 scoped_refptr<DeletionSentinel> deletion_sentinel_; |
250 base::WeakPtrFactory<TaskQueueManager> weak_factory_; | 255 base::WeakPtrFactory<TaskQueueManager> weak_factory_; |
251 | 256 |
252 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); | 257 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); |
253 }; | 258 }; |
254 | 259 |
255 } // namespace scheduler | 260 } // namespace scheduler |
256 | 261 |
257 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ | 262 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ |
OLD | NEW |