| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_WORKER_POOL_MANAGER_H_ |
| 6 #define BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_WORKER_POOL_MANAGER_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 |
| 10 #include <memory> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/base_export.h" |
| 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/task_scheduler/scheduler_lock.h" |
| 18 #include "base/task_scheduler/scheduler_worker_pool_impl.h" |
| 19 #include "base/task_scheduler/task_scheduler.h" |
| 20 |
| 21 namespace base { |
| 22 |
| 23 class SchedulerWorkerPoolParams; |
| 24 class TaskTraits; |
| 25 |
| 26 namespace internal { |
| 27 |
| 28 class DelayedTaskManager; |
| 29 class TaskTracker; |
| 30 |
| 31 // Manages a pool of single-threaded worker pools mapped to one |
| 32 // SingleThreadTaskRunner. |
| 33 // |
| 34 // To maintain the same single thread threading environment for the trait |
| 35 // targeting a SchedulerWorkerPoolImpl, this also maintains the original |
| 36 // incoming SchedulerWorkerPoolParams and the WorkerPoolIndexForTraitsCallback |
| 37 // to create a single thread SchedulerWorkerPoolImpl of the exact same threading |
| 38 // environment. |
| 39 // |
| 40 // A single SingleThreadSchedulerWorkerPoolImplPool maintains a pool of |
| 41 // SchedulerWorkerPoolImpls of SchedulerWorkerPoolParams parameters. These are |
| 42 // held by |worker_pool_impl_pools_| and indexed the same way as |
| 43 // SchedulerWorkerPoolImpls in TaskSchedulerImpl. |
| 44 class BASE_EXPORT SchedulerSingleThreadWorkerPoolManager final { |
| 45 public: |
| 46 SchedulerSingleThreadWorkerPoolManager( |
| 47 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, |
| 48 const TaskScheduler::WorkerPoolIndexForTraitsCallback& |
| 49 worker_pool_index_for_traits_callback, |
| 50 TaskTracker* task_tracker, |
| 51 DelayedTaskManager* delayed_task_manager); |
| 52 ~SchedulerSingleThreadWorkerPoolManager(); |
| 53 |
| 54 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( |
| 55 const TaskTraits& traits); |
| 56 |
| 57 void JoinForTesting(); |
| 58 void WaitForAllWorkersIdleForTesting(); |
| 59 |
| 60 private: |
| 61 class SingleThreadSchedulerWorkerPoolImplPool; |
| 62 |
| 63 const TaskScheduler::WorkerPoolIndexForTraitsCallback |
| 64 worker_pool_index_for_traits_callback_; |
| 65 |
| 66 // Synchronizes access to |worker_pool_impl_pools_|. |
| 67 SchedulerLock lock_; |
| 68 std::vector<std::unique_ptr<SingleThreadSchedulerWorkerPoolImplPool>> |
| 69 worker_pool_impl_pools_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(SchedulerSingleThreadWorkerPoolManager); |
| 72 }; |
| 73 |
| 74 } // namespace internal |
| 75 } // namespace base |
| 76 |
| 77 #endif // BASE_TASK_SCHEDULER_SCHEDULER_SINGLE_THREAD_WORKER_POOL_MANAGER_H_ |
| OLD | NEW |