| 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> |
| 11 #include <stack> | |
| 12 #include <vector> | 11 #include <vector> |
| 13 | 12 |
| 14 #include "base/base_export.h" | 13 #include "base/base_export.h" |
| 15 #include "base/callback.h" | 14 #include "base/callback.h" |
| 16 #include "base/macros.h" | 15 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 18 #include "base/synchronization/condition_variable.h" | 17 #include "base/synchronization/condition_variable.h" |
| 19 #include "base/task_runner.h" | 18 #include "base/task_runner.h" |
| 20 #include "base/task_scheduler/priority_queue.h" | 19 #include "base/task_scheduler/priority_queue.h" |
| 21 #include "base/task_scheduler/scheduler_lock.h" | 20 #include "base/task_scheduler/scheduler_lock.h" |
| 22 #include "base/task_scheduler/scheduler_task_executor.h" | 21 #include "base/task_scheduler/scheduler_task_executor.h" |
| 22 #include "base/task_scheduler/scheduler_unique_stack.h" |
| 23 #include "base/task_scheduler/scheduler_worker_thread.h" | 23 #include "base/task_scheduler/scheduler_worker_thread.h" |
| 24 #include "base/task_scheduler/sequence.h" | 24 #include "base/task_scheduler/sequence.h" |
| 25 #include "base/task_scheduler/task.h" | 25 #include "base/task_scheduler/task.h" |
| 26 #include "base/task_scheduler/task_traits.h" | 26 #include "base/task_scheduler/task_traits.h" |
| 27 #include "base/threading/platform_thread.h" | 27 #include "base/threading/platform_thread.h" |
| 28 | 28 |
| 29 namespace base { | 29 namespace base { |
| 30 namespace internal { | 30 namespace internal { |
| 31 | 31 |
| 32 class DelayedTaskManager; | 32 class DelayedTaskManager; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 std::vector<std::unique_ptr<SchedulerWorkerThread>> worker_threads_; | 109 std::vector<std::unique_ptr<SchedulerWorkerThread>> worker_threads_; |
| 110 | 110 |
| 111 // Synchronizes access to |idle_worker_threads_stack_| and | 111 // Synchronizes access to |idle_worker_threads_stack_| and |
| 112 // |idle_worker_threads_stack_cv_for_testing_|. Has |shared_priority_queue_|'s | 112 // |idle_worker_threads_stack_cv_for_testing_|. Has |shared_priority_queue_|'s |
| 113 // lock as its predecessor so that a thread can be pushed to | 113 // lock as its predecessor so that a thread can be pushed to |
| 114 // |idle_worker_threads_stack_| within the scope of a Transaction (more | 114 // |idle_worker_threads_stack_| within the scope of a Transaction (more |
| 115 // details in GetWork()). | 115 // details in GetWork()). |
| 116 SchedulerLock idle_worker_threads_stack_lock_; | 116 SchedulerLock idle_worker_threads_stack_lock_; |
| 117 | 117 |
| 118 // Stack of idle worker threads. | 118 // Stack of idle worker threads. |
| 119 std::stack<SchedulerWorkerThread*> idle_worker_threads_stack_; | 119 SchedulerUniqueStack<SchedulerWorkerThread*> idle_worker_threads_stack_; |
| 120 | 120 |
| 121 // Signaled when all worker threads become idle. | 121 // Signaled when all worker threads become idle. |
| 122 std::unique_ptr<ConditionVariable> idle_worker_threads_stack_cv_for_testing_; | 122 std::unique_ptr<ConditionVariable> idle_worker_threads_stack_cv_for_testing_; |
| 123 | 123 |
| 124 // Signaled once JoinForTesting() has returned. | 124 // Signaled once JoinForTesting() has returned. |
| 125 WaitableEvent join_for_testing_returned_; | 125 WaitableEvent join_for_testing_returned_; |
| 126 | 126 |
| 127 // Delegate for all worker threads in this pool. | 127 // Delegate for all worker threads in this pool. |
| 128 std::unique_ptr<SchedulerWorkerThread::Delegate> worker_thread_delegate_; | 128 std::unique_ptr<SchedulerWorkerThread::Delegate> worker_thread_delegate_; |
| 129 | 129 |
| 130 TaskTracker* const task_tracker_; | 130 TaskTracker* const task_tracker_; |
| 131 DelayedTaskManager* const delayed_task_manager_; | 131 DelayedTaskManager* const delayed_task_manager_; |
| 132 | 132 |
| 133 DISALLOW_COPY_AND_ASSIGN(SchedulerThreadPool); | 133 DISALLOW_COPY_AND_ASSIGN(SchedulerThreadPool); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 } // namespace internal | 136 } // namespace internal |
| 137 } // namespace base | 137 } // namespace base |
| 138 | 138 |
| 139 #endif // BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ | 139 #endif // BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ |
| OLD | NEW |