OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/base_export.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/task_runner.h" |
| 16 #include "base/task_scheduler/delayed_task_manager.h" |
| 17 #include "base/task_scheduler/scheduler_thread_pool_impl.h" |
| 18 #include "base/task_scheduler/sequence.h" |
| 19 #include "base/task_scheduler/task_scheduler.h" |
| 20 #include "base/task_scheduler/task_tracker.h" |
| 21 #include "base/task_scheduler/task_traits.h" |
| 22 |
| 23 namespace base { |
| 24 namespace internal { |
| 25 |
| 26 // Default TaskScheduler implementation. This class is thread-safe. |
| 27 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { |
| 28 public: |
| 29 // Creates a TaskSchedulerImpl. CHECKs on failure to do so. |
| 30 TaskSchedulerImpl(); |
| 31 |
| 32 // Destroying a TaskSchedulerImpl is not allowed in production; it is always |
| 33 // leaked. In tests, it can only be destroyed after JoinForTesting() has |
| 34 // returned. |
| 35 ~TaskSchedulerImpl() override; |
| 36 |
| 37 static std::unique_ptr<TaskSchedulerImpl> Create(); |
| 38 |
| 39 // TaskScheduler: |
| 40 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 41 const TaskTraits& traits, |
| 42 ExecutionMode execution_mode) override; |
| 43 void Shutdown() override; |
| 44 |
| 45 // Joins all threads of this scheduler. Tasks that are already running are |
| 46 // allowed to complete their execution. This can only be called once. |
| 47 void JoinForTesting(); |
| 48 |
| 49 private: |
| 50 void Initialize(); |
| 51 |
| 52 // Returns the thread pool that runs Tasks with |traits|. |
| 53 SchedulerThreadPool* GetThreadPoolForTraits(const TaskTraits& traits); |
| 54 |
| 55 // Callback invoked when a non-single-thread |sequence| isn't empty after a |
| 56 // worker thread pops a Task from it. |
| 57 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); |
| 58 |
| 59 TaskTracker task_tracker_; |
| 60 DelayedTaskManager delayed_task_manager_; |
| 61 |
| 62 // Thread pool for BACKGROUND Tasks without file I/O. |
| 63 std::unique_ptr<SchedulerThreadPoolImpl> background_thread_pool_; |
| 64 |
| 65 // Thread pool for BACKGROUND Tasks with file I/O. |
| 66 std::unique_ptr<SchedulerThreadPoolImpl> background_file_io_thread_pool_; |
| 67 |
| 68 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks without file I/O. |
| 69 std::unique_ptr<SchedulerThreadPoolImpl> normal_thread_pool_; |
| 70 |
| 71 // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks with file I/O. |
| 72 std::unique_ptr<SchedulerThreadPoolImpl> normal_file_io_thread_pool_; |
| 73 |
| 74 #if DCHECK_IS_ON() |
| 75 // Signaled once JoinForTesting() has returned. |
| 76 WaitableEvent join_for_testing_returned_; |
| 77 #endif |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); |
| 80 }; |
| 81 |
| 82 } // namespace internal |
| 83 } // namespace base |
| 84 |
| 85 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
OLD | NEW |