Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: base/task_scheduler/task_scheduler_impl.h

Issue 2146223002: Refactor WorkerPoolCreationArgs to a Read-Only WorkerPoolParams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 #include "base/task_scheduler/sequence.h" 23 #include "base/task_scheduler/sequence.h"
24 #include "base/task_scheduler/task_scheduler.h" 24 #include "base/task_scheduler/task_scheduler.h"
25 #include "base/task_scheduler/task_tracker.h" 25 #include "base/task_scheduler/task_tracker.h"
26 #include "base/task_scheduler/task_traits.h" 26 #include "base/task_scheduler/task_traits.h"
27 #include "base/threading/thread.h" 27 #include "base/threading/thread.h"
28 28
29 namespace base { 29 namespace base {
30 namespace internal { 30 namespace internal {
31 31
32 class SchedulerServiceThread; 32 class SchedulerServiceThread;
33 class WorkerPoolParams;
33 34
34 // Default TaskScheduler implementation. This class is thread-safe. 35 // Default TaskScheduler implementation. This class is thread-safe.
35 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { 36 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
36 public: 37 public:
37 struct WorkerPoolCreationArgs {
38 // Name of the pool. Used to label the pool's threads.
39 std::string name;
40
41 // Priority of the pool's threads.
42 ThreadPriority thread_priority;
43
44 // Whether I/O is allowed in the pool.
45 SchedulerWorkerPoolImpl::IORestriction io_restriction;
46
47 // Maximum number of threads in the pool.
48 size_t max_threads;
49 };
50
51 // Returns the index of the worker pool in which a task with |traits| should 38 // Returns the index of the worker pool in which a task with |traits| should
52 // run. This should be coded in a future-proof way: new traits should 39 // run. This should be coded in a future-proof way: new traits should
53 // gracefully map to a default pool. 40 // gracefully map to a default pool.
54 using WorkerPoolIndexForTraitsCallback = 41 using WorkerPoolIndexForTraitsCallback =
55 Callback<size_t(const TaskTraits& traits)>; 42 Callback<size_t(const TaskTraits& traits)>;
56 43
57 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure. 44 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure.
58 // |worker_pools| describes the worker pools to create. 45 // |worker_pools| describes the worker pools to create.
59 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools| 46 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools|
60 // of the worker pool in which a task with given traits should run. 47 // of the worker pool in which a task with given traits should run.
61 static std::unique_ptr<TaskSchedulerImpl> Create( 48 static std::unique_ptr<TaskSchedulerImpl> Create(
62 const std::vector<WorkerPoolCreationArgs>& worker_pools, 49 const std::vector<WorkerPoolParams>& worker_pools,
63 const WorkerPoolIndexForTraitsCallback& 50 const WorkerPoolIndexForTraitsCallback&
64 worker_pool_index_for_traits_callback); 51 worker_pool_index_for_traits_callback);
65 52
66 // Destroying a TaskSchedulerImpl is not allowed in production; it is always 53 // Destroying a TaskSchedulerImpl is not allowed in production; it is always
67 // leaked. In tests, it can only be destroyed after JoinForTesting() has 54 // leaked. In tests, it can only be destroyed after JoinForTesting() has
68 // returned. 55 // returned.
69 ~TaskSchedulerImpl() override; 56 ~TaskSchedulerImpl() override;
70 57
71 // TaskScheduler: 58 // TaskScheduler:
72 void PostTaskWithTraits(const tracked_objects::Location& from_here, 59 void PostTaskWithTraits(const tracked_objects::Location& from_here,
73 const TaskTraits& traits, 60 const TaskTraits& traits,
74 const Closure& task) override; 61 const Closure& task) override;
75 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( 62 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(
76 const TaskTraits& traits, 63 const TaskTraits& traits,
77 ExecutionMode execution_mode) override; 64 ExecutionMode execution_mode) override;
78 void Shutdown() override; 65 void Shutdown() override;
79 66
80 // Joins all threads of this scheduler. Tasks that are already running are 67 // Joins all threads of this scheduler. Tasks that are already running are
81 // allowed to complete their execution. This can only be called once. 68 // allowed to complete their execution. This can only be called once.
82 void JoinForTesting(); 69 void JoinForTesting();
83 70
84 private: 71 private:
85 TaskSchedulerImpl(const WorkerPoolIndexForTraitsCallback& 72 TaskSchedulerImpl(const WorkerPoolIndexForTraitsCallback&
86 worker_pool_index_for_traits_callback); 73 worker_pool_index_for_traits_callback);
87 74
88 void Initialize(const std::vector<WorkerPoolCreationArgs>& worker_pools); 75 void Initialize(const std::vector<WorkerPoolParams>& worker_pools);
89 76
90 // Returns the worker pool that runs Tasks with |traits|. 77 // Returns the worker pool that runs Tasks with |traits|.
91 SchedulerWorkerPool* GetWorkerPoolForTraits(const TaskTraits& traits); 78 SchedulerWorkerPool* GetWorkerPoolForTraits(const TaskTraits& traits);
92 79
93 // Callback invoked when a non-single-thread |sequence| isn't empty after a 80 // Callback invoked when a non-single-thread |sequence| isn't empty after a
94 // worker pops a Task from it. 81 // worker pops a Task from it.
95 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); 82 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence);
96 83
97 // Callback invoked when the delayed run time is changed from the 84 // Callback invoked when the delayed run time is changed from the
98 // DelayedTaskManager. 85 // DelayedTaskManager.
(...skipping 10 matching lines...) Expand all
109 WaitableEvent join_for_testing_returned_; 96 WaitableEvent join_for_testing_returned_;
110 #endif 97 #endif
111 98
112 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); 99 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl);
113 }; 100 };
114 101
115 } // namespace internal 102 } // namespace internal
116 } // namespace base 103 } // namespace base
117 104
118 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ 105 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698