OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ | 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ |
6 #define BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ | 6 #define BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 bool PostTaskWithSequence(std::unique_ptr<Task> task, | 83 bool PostTaskWithSequence(std::unique_ptr<Task> task, |
84 scoped_refptr<Sequence> sequence); | 84 scoped_refptr<Sequence> sequence); |
85 | 85 |
86 // SchedulerThreadPoolInterface: | 86 // SchedulerThreadPoolInterface: |
87 void PostTaskWithSequenceNow(std::unique_ptr<Task> task, | 87 void PostTaskWithSequenceNow(std::unique_ptr<Task> task, |
88 scoped_refptr<Sequence> sequence) override; | 88 scoped_refptr<Sequence> sequence) override; |
89 | 89 |
90 private: | 90 private: |
91 class SchedulerWorkerThreadDelegateImpl; | 91 class SchedulerWorkerThreadDelegateImpl; |
92 | 92 |
93 SchedulerThreadPool(const EnqueueSequenceCallback& enqueue_sequence_callback, | 93 SchedulerThreadPool(TaskTracker* task_tracker, |
94 TaskTracker* task_tracker, | |
95 DelayedTaskManager* delayed_task_manager); | 94 DelayedTaskManager* delayed_task_manager); |
96 | 95 |
97 bool Initialize(ThreadPriority thread_priority, size_t max_threads); | 96 bool Initialize(ThreadPriority thread_priority, |
| 97 size_t max_threads, |
| 98 const EnqueueSequenceCallback& enqueue_sequence_callback); |
98 | 99 |
99 // Wakes up the last thread from this thread pool to go idle, if any. | 100 // Wakes up the last thread from this thread pool to go idle, if any. |
100 void WakeUpOneThread(); | 101 void WakeUpOneThread(); |
101 | 102 |
102 // Adds |worker_thread| to |idle_worker_threads_stack_|. | 103 // Adds |worker_thread| to |idle_worker_threads_stack_|. |
103 void AddToIdleWorkerThreadsStack(SchedulerWorkerThread* worker_thread); | 104 void AddToIdleWorkerThreadsStack(SchedulerWorkerThread* worker_thread); |
104 | 105 |
105 // Pops one idle worker thread from |idle_worker_thread_stack_| and returns | 106 // Pops one idle worker thread from |idle_worker_thread_stack_| and returns |
106 // it. Returns nullptr if |idle_worker_thread_stack_| is empty. | 107 // it. Returns nullptr if |idle_worker_thread_stack_| is empty. |
107 SchedulerWorkerThread* PopOneIdleWorkerThread(); | 108 SchedulerWorkerThread* PopOneIdleWorkerThread(); |
(...skipping 14 matching lines...) Expand all Loading... |
122 | 123 |
123 // Stack of idle worker threads. | 124 // Stack of idle worker threads. |
124 SchedulerUniqueStack<SchedulerWorkerThread*> idle_worker_threads_stack_; | 125 SchedulerUniqueStack<SchedulerWorkerThread*> idle_worker_threads_stack_; |
125 | 126 |
126 // Signaled when all worker threads become idle. | 127 // Signaled when all worker threads become idle. |
127 std::unique_ptr<ConditionVariable> idle_worker_threads_stack_cv_for_testing_; | 128 std::unique_ptr<ConditionVariable> idle_worker_threads_stack_cv_for_testing_; |
128 | 129 |
129 // Signaled once JoinForTesting() has returned. | 130 // Signaled once JoinForTesting() has returned. |
130 WaitableEvent join_for_testing_returned_; | 131 WaitableEvent join_for_testing_returned_; |
131 | 132 |
132 // Delegate for all worker threads in this pool. | |
133 std::unique_ptr<SchedulerWorkerThread::Delegate> worker_thread_delegate_; | |
134 | |
135 TaskTracker* const task_tracker_; | 133 TaskTracker* const task_tracker_; |
136 DelayedTaskManager* const delayed_task_manager_; | 134 DelayedTaskManager* const delayed_task_manager_; |
137 | 135 |
138 DISALLOW_COPY_AND_ASSIGN(SchedulerThreadPool); | 136 DISALLOW_COPY_AND_ASSIGN(SchedulerThreadPool); |
139 }; | 137 }; |
140 | 138 |
141 } // namespace internal | 139 } // namespace internal |
142 } // namespace base | 140 } // namespace base |
143 | 141 |
144 #endif // BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ | 142 #endif // BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ |
OLD | NEW |