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

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

Issue 2721553003: Remove SingleThreadTaskRunner Support from SchedulerWorkerPoolImpl (Closed)
Patch Set: Rebase to 08266b3 Created 3 years, 9 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_SCHEDULER_WORKER_POOL_IMPL_H_ 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_
6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 const SchedulerWorkerPoolParams& params, 60 const SchedulerWorkerPoolParams& params,
61 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, 61 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback,
62 TaskTracker* task_tracker, 62 TaskTracker* task_tracker,
63 DelayedTaskManager* delayed_task_manager); 63 DelayedTaskManager* delayed_task_manager);
64 64
65 // SchedulerWorkerPool: 65 // SchedulerWorkerPool:
66 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( 66 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(
67 const TaskTraits& traits) override; 67 const TaskTraits& traits) override;
68 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( 68 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits(
69 const TaskTraits& traits) override; 69 const TaskTraits& traits) override;
70 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits(
71 const TaskTraits& traits) override;
72 void ReEnqueueSequence(scoped_refptr<Sequence> sequence, 70 void ReEnqueueSequence(scoped_refptr<Sequence> sequence,
73 const SequenceSortKey& sequence_sort_key) override; 71 const SequenceSortKey& sequence_sort_key) override;
74 bool PostTaskWithSequence(std::unique_ptr<Task> task, 72 bool PostTaskWithSequence(std::unique_ptr<Task> task,
75 scoped_refptr<Sequence> sequence, 73 scoped_refptr<Sequence> sequence) override;
76 SchedulerWorker* worker) override;
77 void PostTaskWithSequenceNow(std::unique_ptr<Task> task, 74 void PostTaskWithSequenceNow(std::unique_ptr<Task> task,
78 scoped_refptr<Sequence> sequence, 75 scoped_refptr<Sequence> sequence) override;
79 SchedulerWorker* worker) override;
80 76
81 const HistogramBase* num_tasks_before_detach_histogram() const { 77 const HistogramBase* num_tasks_before_detach_histogram() const {
82 return num_tasks_before_detach_histogram_; 78 return num_tasks_before_detach_histogram_;
83 } 79 }
84 80
85 const HistogramBase* num_tasks_between_waits_histogram() const { 81 const HistogramBase* num_tasks_between_waits_histogram() const {
86 return num_tasks_between_waits_histogram_; 82 return num_tasks_between_waits_histogram_;
87 } 83 }
88 84
89 void GetHistograms(std::vector<const HistogramBase*>* histograms) const; 85 void GetHistograms(std::vector<const HistogramBase*>* histograms) const;
(...skipping 14 matching lines...) Expand all
104 // TimeDelta::Max(), the test must call this before JoinForTesting() to reduce 100 // TimeDelta::Max(), the test must call this before JoinForTesting() to reduce
105 // the chance of thread detachment during the process of joining all of the 101 // the chance of thread detachment during the process of joining all of the
106 // threads, and as a result, threads running after JoinForTesting(). 102 // threads, and as a result, threads running after JoinForTesting().
107 void DisallowWorkerDetachmentForTesting(); 103 void DisallowWorkerDetachmentForTesting();
108 104
109 // Returns the number of workers alive in this worker pool. The value may 105 // Returns the number of workers alive in this worker pool. The value may
110 // change if workers are woken up or detached during this call. 106 // change if workers are woken up or detached during this call.
111 size_t NumberOfAliveWorkersForTesting(); 107 size_t NumberOfAliveWorkersForTesting();
112 108
113 private: 109 private:
114 class SchedulerSingleThreadTaskRunner;
115 class SchedulerWorkerDelegateImpl; 110 class SchedulerWorkerDelegateImpl;
116 111
117 SchedulerWorkerPoolImpl(const SchedulerWorkerPoolParams& params, 112 SchedulerWorkerPoolImpl(const SchedulerWorkerPoolParams& params,
118 TaskTracker* task_tracker, 113 TaskTracker* task_tracker,
119 DelayedTaskManager* delayed_task_manager); 114 DelayedTaskManager* delayed_task_manager);
120 115
121 bool Initialize( 116 bool Initialize(
122 const SchedulerWorkerPoolParams& params, 117 const SchedulerWorkerPoolParams& params,
123 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback); 118 const ReEnqueueSequenceCallback& re_enqueue_sequence_callback);
124 119
125 // Wakes up |worker|.
126 void WakeUpWorker(SchedulerWorker* worker);
127
128 // Wakes up the last worker from this worker pool to go idle, if any. 120 // Wakes up the last worker from this worker pool to go idle, if any.
129 void WakeUpOneWorker(); 121 void WakeUpOneWorker();
130 122
131 // Adds |worker| to |idle_workers_stack_|. 123 // Adds |worker| to |idle_workers_stack_|.
132 void AddToIdleWorkersStack(SchedulerWorker* worker); 124 void AddToIdleWorkersStack(SchedulerWorker* worker);
133 125
134 // Peeks from |idle_workers_stack_|. 126 // Peeks from |idle_workers_stack_|.
135 const SchedulerWorker* PeekAtIdleWorkersStack() const; 127 const SchedulerWorker* PeekAtIdleWorkersStack() const;
136 128
137 // Removes |worker| from |idle_workers_stack_|. 129 // Removes |worker| from |idle_workers_stack_|.
138 void RemoveFromIdleWorkersStack(SchedulerWorker* worker); 130 void RemoveFromIdleWorkersStack(SchedulerWorker* worker);
139 131
140 // Returns true if worker thread detachment is permitted. 132 // Returns true if worker thread detachment is permitted.
141 bool CanWorkerDetachForTesting(); 133 bool CanWorkerDetachForTesting();
142 134
143 // The name of this worker pool, used to label its worker threads. 135 // The name of this worker pool, used to label its worker threads.
144 const std::string name_; 136 const std::string name_;
145 137
146 // All worker owned by this worker pool. Only modified during initialization 138 // All worker owned by this worker pool. Only modified during initialization
147 // of the worker pool. 139 // of the worker pool.
148 std::vector<scoped_refptr<SchedulerWorker>> workers_; 140 std::vector<scoped_refptr<SchedulerWorker>> workers_;
149 141
150 // Synchronizes access to |next_worker_index_|.
151 SchedulerLock next_worker_index_lock_;
152
153 // Index of the worker that will be assigned to the next single-threaded
154 // TaskRunner returned by this pool.
155 size_t next_worker_index_ = 0;
156
157 // PriorityQueue from which all threads of this worker pool get work. 142 // PriorityQueue from which all threads of this worker pool get work.
158 PriorityQueue shared_priority_queue_; 143 PriorityQueue shared_priority_queue_;
159 144
160 // Suggested reclaim time for workers. 145 // Suggested reclaim time for workers.
161 const TimeDelta suggested_reclaim_time_; 146 const TimeDelta suggested_reclaim_time_;
162 147
163 // Synchronizes access to |idle_workers_stack_| and 148 // Synchronizes access to |idle_workers_stack_| and
164 // |idle_workers_stack_cv_for_testing_|. Has |shared_priority_queue_|'s 149 // |idle_workers_stack_cv_for_testing_|. Has |shared_priority_queue_|'s
165 // lock as its predecessor so that a worker can be pushed to 150 // lock as its predecessor so that a worker can be pushed to
166 // |idle_workers_stack_| within the scope of a Transaction (more 151 // |idle_workers_stack_| within the scope of a Transaction (more
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 TaskTracker* const task_tracker_; 189 TaskTracker* const task_tracker_;
205 DelayedTaskManager* const delayed_task_manager_; 190 DelayedTaskManager* const delayed_task_manager_;
206 191
207 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerPoolImpl); 192 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerPoolImpl);
208 }; 193 };
209 194
210 } // namespace internal 195 } // namespace internal
211 } // namespace base 196 } // namespace base
212 197
213 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_ 198 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698