| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 public: | 37 public: |
| 38 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure. | 38 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure. |
| 39 // |worker_pool_params_vector| describes the worker pools to create. | 39 // |worker_pool_params_vector| describes the worker pools to create. |
| 40 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools| | 40 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools| |
| 41 // of the worker pool in which a task with given traits should run. | 41 // of the worker pool in which a task with given traits should run. |
| 42 static std::unique_ptr<TaskSchedulerImpl> Create( | 42 static std::unique_ptr<TaskSchedulerImpl> Create( |
| 43 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, | 43 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, |
| 44 const WorkerPoolIndexForTraitsCallback& | 44 const WorkerPoolIndexForTraitsCallback& |
| 45 worker_pool_index_for_traits_callback); | 45 worker_pool_index_for_traits_callback); |
| 46 | 46 |
| 47 // Destroying a TaskSchedulerImpl is not allowed in production; it is always | |
| 48 // leaked. In tests, it can only be destroyed after JoinForTesting() has | |
| 49 // returned. | |
| 50 ~TaskSchedulerImpl() override; | 47 ~TaskSchedulerImpl() override; |
| 51 | 48 |
| 52 // TaskScheduler: | 49 // TaskScheduler: |
| 53 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here, | 50 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here, |
| 54 const TaskTraits& traits, | 51 const TaskTraits& traits, |
| 55 const Closure& task, | 52 const Closure& task, |
| 56 TimeDelta delay) override; | 53 TimeDelta delay) override; |
| 57 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 54 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 58 const TaskTraits& traits) override; | 55 const TaskTraits& traits) override; |
| 59 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( | 56 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( |
| 60 const TaskTraits& traits) override; | 57 const TaskTraits& traits) override; |
| 61 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( | 58 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( |
| 62 const TaskTraits& traits) override; | 59 const TaskTraits& traits) override; |
| 63 std::vector<const HistogramBase*> GetHistograms() const override; | 60 std::vector<const HistogramBase*> GetHistograms() const override; |
| 64 void Shutdown() override; | 61 void Shutdown() override; |
| 65 void FlushForTesting() override; | 62 void FlushForTesting() override; |
| 66 | 63 void JoinForTesting() override; |
| 67 // Joins all threads. Tasks that are already running are allowed to complete | |
| 68 // their execution. This can only be called once. | |
| 69 void JoinForTesting(); | |
| 70 | 64 |
| 71 private: | 65 private: |
| 72 explicit TaskSchedulerImpl(const WorkerPoolIndexForTraitsCallback& | 66 explicit TaskSchedulerImpl(const WorkerPoolIndexForTraitsCallback& |
| 73 worker_pool_index_for_traits_callback); | 67 worker_pool_index_for_traits_callback); |
| 74 | 68 |
| 75 void Initialize( | 69 void Initialize( |
| 76 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector); | 70 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector); |
| 77 | 71 |
| 78 // Returns the worker pool that runs Tasks with |traits|. | 72 // Returns the worker pool that runs Tasks with |traits|. |
| 79 SchedulerWorkerPool* GetWorkerPoolForTraits(const TaskTraits& traits); | 73 SchedulerWorkerPool* GetWorkerPoolForTraits(const TaskTraits& traits); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 93 AtomicFlag join_for_testing_returned_; | 87 AtomicFlag join_for_testing_returned_; |
| 94 #endif | 88 #endif |
| 95 | 89 |
| 96 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); | 90 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); |
| 97 }; | 91 }; |
| 98 | 92 |
| 99 } // namespace internal | 93 } // namespace internal |
| 100 } // namespace base | 94 } // namespace base |
| 101 | 95 |
| 102 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | 96 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| OLD | NEW |