| 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_TASK_SCHEDULER_IMPL_H_ | 5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/task_runner.h" | 15 #include "base/task_runner.h" |
| 16 #include "base/task_scheduler/delayed_task_manager.h" | 16 #include "base/task_scheduler/delayed_task_manager.h" |
| 17 #include "base/task_scheduler/sequence.h" | 17 #include "base/task_scheduler/sequence.h" |
| 18 #include "base/task_scheduler/task_scheduler.h" | 18 #include "base/task_scheduler/task_scheduler.h" |
| 19 #include "base/task_scheduler/task_tracker.h" | 19 #include "base/task_scheduler/task_tracker.h" |
| 20 #include "base/task_scheduler/task_traits.h" | 20 #include "base/task_scheduler/task_traits.h" |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 namespace internal { | 23 namespace internal { |
| 24 | 24 |
| 25 class SchedulerServiceThread; | 25 class SchedulerServiceThread; |
| 26 class SchedulerThreadPoolImpl; | 26 class SchedulerWorkerPoolImpl; |
| 27 | 27 |
| 28 // Default TaskScheduler implementation. This class is thread-safe. | 28 // Default TaskScheduler implementation. This class is thread-safe. |
| 29 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { | 29 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { |
| 30 public: | 30 public: |
| 31 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure to | 31 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure to |
| 32 // do so (never returns null). | 32 // do so (never returns null). |
| 33 static std::unique_ptr<TaskSchedulerImpl> Create(); | 33 static std::unique_ptr<TaskSchedulerImpl> Create(); |
| 34 | 34 |
| 35 // Destroying a TaskSchedulerImpl is not allowed in production; it is always | 35 // Destroying a TaskSchedulerImpl is not allowed in production; it is always |
| 36 // leaked. In tests, it can only be destroyed after JoinForTesting() has | 36 // leaked. In tests, it can only be destroyed after JoinForTesting() has |
| (...skipping 11 matching lines...) Expand all Loading... |
| 48 | 48 |
| 49 // Joins all threads of this scheduler. Tasks that are already running are | 49 // Joins all threads of this scheduler. Tasks that are already running are |
| 50 // allowed to complete their execution. This can only be called once. | 50 // allowed to complete their execution. This can only be called once. |
| 51 void JoinForTesting(); | 51 void JoinForTesting(); |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 TaskSchedulerImpl(); | 54 TaskSchedulerImpl(); |
| 55 | 55 |
| 56 void Initialize(); | 56 void Initialize(); |
| 57 | 57 |
| 58 // Returns the thread pool that runs Tasks with |traits|. | 58 // Returns the worker pool that runs Tasks with |traits|. |
| 59 SchedulerThreadPool* GetThreadPoolForTraits(const TaskTraits& traits); | 59 SchedulerWorkerPool* GetWorkerPoolForTraits(const TaskTraits& traits); |
| 60 | 60 |
| 61 // Callback invoked when a non-single-thread |sequence| isn't empty after a | 61 // Callback invoked when a non-single-thread |sequence| isn't empty after a |
| 62 // worker thread pops a Task from it. | 62 // worker thread pops a Task from it. |
| 63 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); | 63 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); |
| 64 | 64 |
| 65 // Callback invoked when the delayed run time is changed from the | 65 // Callback invoked when the delayed run time is changed from the |
| 66 // DelayedTaskManager. | 66 // DelayedTaskManager. |
| 67 void OnDelayedRunTimeUpdated(); | 67 void OnDelayedRunTimeUpdated(); |
| 68 | 68 |
| 69 TaskTracker task_tracker_; | 69 TaskTracker task_tracker_; |
| 70 DelayedTaskManager delayed_task_manager_; | 70 DelayedTaskManager delayed_task_manager_; |
| 71 | 71 |
| 72 // Thread pool for BACKGROUND Tasks without file I/O. | 72 // Worker pool for BACKGROUND Tasks without file I/O. |
| 73 std::unique_ptr<SchedulerThreadPoolImpl> background_thread_pool_; | 73 std::unique_ptr<SchedulerWorkerPoolImpl> background_worker_pool_; |
| 74 | 74 |
| 75 // Thread pool for BACKGROUND Tasks with file I/O. | 75 // Worker pool for BACKGROUND Tasks with file I/O. |
| 76 std::unique_ptr<SchedulerThreadPoolImpl> background_file_io_thread_pool_; | 76 std::unique_ptr<SchedulerWorkerPoolImpl> background_file_io_worker_pool_; |
| 77 | 77 |
| 78 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks without file I/O. | 78 // Worker pool for USER_VISIBLE and USER_BLOCKING Tasks without file I/O. |
| 79 std::unique_ptr<SchedulerThreadPoolImpl> normal_thread_pool_; | 79 std::unique_ptr<SchedulerWorkerPoolImpl> normal_worker_pool_; |
| 80 | 80 |
| 81 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks with file I/O. | 81 // Worker pool for USER_VISIBLE and USER_BLOCKING Tasks with file I/O. |
| 82 std::unique_ptr<SchedulerThreadPoolImpl> normal_file_io_thread_pool_; | 82 std::unique_ptr<SchedulerWorkerPoolImpl> normal_file_io_worker_pool_; |
| 83 | 83 |
| 84 std::unique_ptr<SchedulerServiceThread> service_thread_; | 84 std::unique_ptr<SchedulerServiceThread> service_thread_; |
| 85 | 85 |
| 86 #if DCHECK_IS_ON() | 86 #if DCHECK_IS_ON() |
| 87 // Signaled once JoinForTesting() has returned. | 87 // Signaled once JoinForTesting() has returned. |
| 88 WaitableEvent join_for_testing_returned_; | 88 WaitableEvent join_for_testing_returned_; |
| 89 #endif | 89 #endif |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); | 91 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 } // namespace internal | 94 } // namespace internal |
| 95 } // namespace base | 95 } // namespace base |
| 96 | 96 |
| 97 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | 97 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| OLD | NEW |