| 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_WORKER_POOL_IMPL_H_ | 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ |
| 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ | 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "base/task_scheduler/sequence.h" | 27 #include "base/task_scheduler/sequence.h" |
| 28 #include "base/task_scheduler/task.h" | 28 #include "base/task_scheduler/task.h" |
| 29 #include "base/task_scheduler/task_traits.h" | 29 #include "base/task_scheduler/task_traits.h" |
| 30 #include "base/threading/platform_thread.h" | 30 #include "base/threading/platform_thread.h" |
| 31 | 31 |
| 32 namespace base { | 32 namespace base { |
| 33 namespace internal { | 33 namespace internal { |
| 34 | 34 |
| 35 class DelayedTaskManager; | 35 class DelayedTaskManager; |
| 36 class TaskTracker; | 36 class TaskTracker; |
| 37 class WorkerPoolParams; |
| 37 | 38 |
| 38 // A pool of workers that run Tasks. This class is thread-safe. | 39 // A pool of workers that run Tasks. This class is thread-safe. |
| 39 class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool { | 40 class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool { |
| 40 public: | 41 public: |
| 41 enum class IORestriction { | 42 enum class IORestriction { |
| 42 ALLOWED, | 43 ALLOWED, |
| 43 DISALLOWED, | 44 DISALLOWED, |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 // Callback invoked when a Sequence isn't empty after a worker pops a Task | 47 // Callback invoked when a Sequence isn't empty after a worker pops a Task |
| 47 // from it. | 48 // from it. |
| 48 using ReEnqueueSequenceCallback = Callback<void(scoped_refptr<Sequence>)>; | 49 using ReEnqueueSequenceCallback = Callback<void(scoped_refptr<Sequence>)>; |
| 49 | 50 |
| 50 // Destroying a SchedulerWorkerPoolImpl returned by Create() is not allowed in | 51 // Destroying a SchedulerWorkerPoolImpl returned by Create() is not allowed in |
| 51 // production; it is always leaked. In tests, it can only be destroyed after | 52 // production; it is always leaked. In tests, it can only be destroyed after |
| 52 // JoinForTesting() has returned. | 53 // JoinForTesting() has returned. |
| 53 ~SchedulerWorkerPoolImpl() override; | 54 ~SchedulerWorkerPoolImpl() override; |
| 54 | 55 |
| 55 // Creates a SchedulerWorkerPoolImpl labeled |name| with up to |max_threads| | 56 // Creates a SchedulerWorkerPoolImpl following the |worker_pool_params| |
| 56 // threads of priority |thread_priority|. |io_restriction| indicates whether | 57 // specification. |re_enqueue_sequence_callback| will be invoked after a |
| 57 // Tasks on the constructed worker pool are allowed to make I/O calls. | 58 // worker of this worker pool tries to run a Task. |task_tracker| is used to |
| 58 // |re_enqueue_sequence_callback| will be invoked after a worker of this | 59 // handle shutdown behavior of Tasks. |delayed_task_manager| handles Tasks |
| 59 // worker pool tries to run a Task. |task_tracker| is used to handle shutdown | 60 // posted with a delay. Returns nullptr on failure to create a worker pool |
| 60 // behavior of Tasks. |delayed_task_manager| handles Tasks posted with a | 61 // with at least one thread. |
| 61 // delay. Returns nullptr on failure to create a worker pool with at least one | |
| 62 // thread. | |
| 63 static std::unique_ptr<SchedulerWorkerPoolImpl> Create( | 62 static std::unique_ptr<SchedulerWorkerPoolImpl> Create( |
| 64 StringPiece name, | 63 const WorkerPoolParams& worker_pool_params, |
| 65 ThreadPriority thread_priority, | |
| 66 size_t max_threads, | |
| 67 IORestriction io_restriction, | |
| 68 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, | 64 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, |
| 69 TaskTracker* task_tracker, | 65 TaskTracker* task_tracker, |
| 70 DelayedTaskManager* delayed_task_manager); | 66 DelayedTaskManager* delayed_task_manager); |
| 71 | 67 |
| 72 // Waits until all workers are idle. | 68 // Waits until all workers are idle. |
| 73 void WaitForAllWorkersIdleForTesting(); | 69 void WaitForAllWorkersIdleForTesting(); |
| 74 | 70 |
| 75 // Joins all workers of this worker pool. Tasks that are already running are | 71 // Joins all workers of this worker pool. Tasks that are already running are |
| 76 // allowed to complete their execution. This can only be called once. | 72 // allowed to complete their execution. This can only be called once. |
| 77 void JoinForTesting(); | 73 void JoinForTesting(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 TaskTracker* const task_tracker_; | 151 TaskTracker* const task_tracker_; |
| 156 DelayedTaskManager* const delayed_task_manager_; | 152 DelayedTaskManager* const delayed_task_manager_; |
| 157 | 153 |
| 158 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerPoolImpl); | 154 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerPoolImpl); |
| 159 }; | 155 }; |
| 160 | 156 |
| 161 } // namespace internal | 157 } // namespace internal |
| 162 } // namespace base | 158 } // namespace base |
| 163 | 159 |
| 164 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ | 160 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ |
| OLD | NEW |