| 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 <map> |
| 8 #include <memory> | 9 #include <memory> |
| 10 #include <string> |
| 9 | 11 |
| 10 #include "base/base_export.h" | 12 #include "base/base_export.h" |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/macros.h" | 14 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 14 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
| 16 #include "base/task_scheduler/delayed_task_manager.h" | 18 #include "base/task_scheduler/delayed_task_manager.h" |
| 17 #include "base/task_scheduler/sequence.h" | 19 #include "base/task_scheduler/sequence.h" |
| 18 #include "base/task_scheduler/task_scheduler.h" | 20 #include "base/task_scheduler/task_scheduler.h" |
| 19 #include "base/task_scheduler/task_tracker.h" | 21 #include "base/task_scheduler/task_tracker.h" |
| 20 #include "base/task_scheduler/task_traits.h" | 22 #include "base/task_scheduler/task_traits.h" |
| 21 | 23 |
| 22 namespace base { | 24 namespace base { |
| 23 namespace internal { | 25 namespace internal { |
| 24 | 26 |
| 25 class SchedulerServiceThread; | 27 class SchedulerServiceThread; |
| 26 class SchedulerThreadPoolImpl; | 28 class SchedulerThreadPoolImpl; |
| 27 | 29 |
| 28 // Default TaskScheduler implementation. This class is thread-safe. | 30 // Default TaskScheduler implementation. This class is thread-safe. |
| 29 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { | 31 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { |
| 30 public: | 32 public: |
| 31 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure to | 33 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure |
| 32 // do so (never returns null). | 34 // (never returns null). |variation_params| is used to configure the scheduler |
| 33 static std::unique_ptr<TaskSchedulerImpl> Create(); | 35 // (can be empty). |
| 36 static std::unique_ptr<TaskSchedulerImpl> Create( |
| 37 const std::map<std::string, std::string>& variation_params); |
| 34 | 38 |
| 35 // Destroying a TaskSchedulerImpl is not allowed in production; it is always | 39 // Destroying a TaskSchedulerImpl is not allowed in production; it is always |
| 36 // leaked. In tests, it can only be destroyed after JoinForTesting() has | 40 // leaked. In tests, it can only be destroyed after JoinForTesting() has |
| 37 // returned. | 41 // returned. |
| 38 ~TaskSchedulerImpl() override; | 42 ~TaskSchedulerImpl() override; |
| 39 | 43 |
| 40 // TaskScheduler: | 44 // TaskScheduler: |
| 41 void PostTaskWithTraits(const tracked_objects::Location& from_here, | 45 void PostTaskWithTraits(const tracked_objects::Location& from_here, |
| 42 const TaskTraits& traits, | 46 const TaskTraits& traits, |
| 43 const Closure& task) override; | 47 const Closure& task) override; |
| 44 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 48 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 45 const TaskTraits& traits, | 49 const TaskTraits& traits, |
| 46 ExecutionMode execution_mode) override; | 50 ExecutionMode execution_mode) override; |
| 47 void Shutdown() override; | 51 void Shutdown() override; |
| 48 | 52 |
| 49 // Joins all threads of this scheduler. Tasks that are already running are | 53 // Joins all threads of this scheduler. Tasks that are already running are |
| 50 // allowed to complete their execution. This can only be called once. | 54 // allowed to complete their execution. This can only be called once. |
| 51 void JoinForTesting(); | 55 void JoinForTesting(); |
| 52 | 56 |
| 53 private: | 57 private: |
| 54 TaskSchedulerImpl(); | 58 TaskSchedulerImpl(); |
| 55 | 59 |
| 56 void Initialize(); | 60 void Initialize(const std::map<std::string, std::string>& variation_params); |
| 57 | 61 |
| 58 // Returns the thread pool that runs Tasks with |traits|. | 62 // Returns the thread pool that runs Tasks with |traits|. |
| 59 SchedulerThreadPool* GetThreadPoolForTraits(const TaskTraits& traits); | 63 SchedulerThreadPool* GetThreadPoolForTraits(const TaskTraits& traits); |
| 60 | 64 |
| 61 // Callback invoked when a non-single-thread |sequence| isn't empty after a | 65 // Callback invoked when a non-single-thread |sequence| isn't empty after a |
| 62 // worker thread pops a Task from it. | 66 // worker thread pops a Task from it. |
| 63 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); | 67 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); |
| 64 | 68 |
| 65 // Callback invoked when the delayed run time is changed from the | 69 // Callback invoked when the delayed run time is changed from the |
| 66 // DelayedTaskManager. | 70 // DelayedTaskManager. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 88 WaitableEvent join_for_testing_returned_; | 92 WaitableEvent join_for_testing_returned_; |
| 89 #endif | 93 #endif |
| 90 | 94 |
| 91 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); | 95 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); |
| 92 }; | 96 }; |
| 93 | 97 |
| 94 } // namespace internal | 98 } // namespace internal |
| 95 } // namespace base | 99 } // namespace base |
| 96 | 100 |
| 97 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | 101 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| OLD | NEW |