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

Side by Side Diff: base/threading/sequenced_worker_pool.cc

Issue 2823103003: Introduce TaskRunner::RunsTasksInCurrentSequence() (Closed)
Patch Set: fixed build error and commments Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/threading/sequenced_worker_pool.h" 5 #include "base/threading/sequenced_worker_pool.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 class SequencedWorkerPoolTaskRunner : public TaskRunner { 138 class SequencedWorkerPoolTaskRunner : public TaskRunner {
139 public: 139 public:
140 SequencedWorkerPoolTaskRunner( 140 SequencedWorkerPoolTaskRunner(
141 scoped_refptr<SequencedWorkerPool> pool, 141 scoped_refptr<SequencedWorkerPool> pool,
142 SequencedWorkerPool::WorkerShutdown shutdown_behavior); 142 SequencedWorkerPool::WorkerShutdown shutdown_behavior);
143 143
144 // TaskRunner implementation 144 // TaskRunner implementation
145 bool PostDelayedTask(const tracked_objects::Location& from_here, 145 bool PostDelayedTask(const tracked_objects::Location& from_here,
146 OnceClosure task, 146 OnceClosure task,
147 TimeDelta delay) override; 147 TimeDelta delay) override;
148 bool RunsTasksOnCurrentThread() const override; 148 bool RunsTasksInCurrentSequence() const override;
149 149
150 private: 150 private:
151 ~SequencedWorkerPoolTaskRunner() override; 151 ~SequencedWorkerPoolTaskRunner() override;
152 152
153 const scoped_refptr<SequencedWorkerPool> pool_; 153 const scoped_refptr<SequencedWorkerPool> pool_;
154 154
155 const SequencedWorkerPool::WorkerShutdown shutdown_behavior_; 155 const SequencedWorkerPool::WorkerShutdown shutdown_behavior_;
156 156
157 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolTaskRunner); 157 DISALLOW_COPY_AND_ASSIGN(SequencedWorkerPoolTaskRunner);
158 }; 158 };
(...skipping 10 matching lines...) Expand all
169 const tracked_objects::Location& from_here, 169 const tracked_objects::Location& from_here,
170 OnceClosure task, 170 OnceClosure task,
171 TimeDelta delay) { 171 TimeDelta delay) {
172 if (delay.is_zero()) { 172 if (delay.is_zero()) {
173 return pool_->PostWorkerTaskWithShutdownBehavior(from_here, std::move(task), 173 return pool_->PostWorkerTaskWithShutdownBehavior(from_here, std::move(task),
174 shutdown_behavior_); 174 shutdown_behavior_);
175 } 175 }
176 return pool_->PostDelayedWorkerTask(from_here, std::move(task), delay); 176 return pool_->PostDelayedWorkerTask(from_here, std::move(task), delay);
177 } 177 }
178 178
179 bool SequencedWorkerPoolTaskRunner::RunsTasksOnCurrentThread() const { 179 bool SequencedWorkerPoolTaskRunner::RunsTasksInCurrentSequence() const {
180 return pool_->RunsTasksOnCurrentThread(); 180 return pool_->RunsTasksInCurrentSequence();
181 } 181 }
182 182
183 } // namespace 183 } // namespace
184 184
185 // SequencedWorkerPool::PoolSequencedTaskRunner ------------------------------ 185 // SequencedWorkerPool::PoolSequencedTaskRunner ------------------------------
186 // A SequencedTaskRunner which posts tasks to a SequencedWorkerPool with a 186 // A SequencedTaskRunner which posts tasks to a SequencedWorkerPool with a
187 // fixed sequence token. 187 // fixed sequence token.
188 // 188 //
189 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner). 189 // Note that this class is RefCountedThreadSafe (inherited from TaskRunner).
190 class SequencedWorkerPool::PoolSequencedTaskRunner 190 class SequencedWorkerPool::PoolSequencedTaskRunner
191 : public SequencedTaskRunner { 191 : public SequencedTaskRunner {
192 public: 192 public:
193 PoolSequencedTaskRunner( 193 PoolSequencedTaskRunner(
194 scoped_refptr<SequencedWorkerPool> pool, 194 scoped_refptr<SequencedWorkerPool> pool,
195 SequencedWorkerPool::SequenceToken token, 195 SequencedWorkerPool::SequenceToken token,
196 SequencedWorkerPool::WorkerShutdown shutdown_behavior); 196 SequencedWorkerPool::WorkerShutdown shutdown_behavior);
197 197
198 // TaskRunner implementation 198 // TaskRunner implementation
199 bool PostDelayedTask(const tracked_objects::Location& from_here, 199 bool PostDelayedTask(const tracked_objects::Location& from_here,
200 OnceClosure task, 200 OnceClosure task,
201 TimeDelta delay) override; 201 TimeDelta delay) override;
202 bool RunsTasksOnCurrentThread() const override; 202 bool RunsTasksInCurrentSequence() const override;
203
203 204
204 // SequencedTaskRunner implementation 205 // SequencedTaskRunner implementation
205 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 206 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
206 OnceClosure task, 207 OnceClosure task,
207 TimeDelta delay) override; 208 TimeDelta delay) override;
208 209
209 private: 210 private:
210 ~PoolSequencedTaskRunner() override; 211 ~PoolSequencedTaskRunner() override;
211 212
212 const scoped_refptr<SequencedWorkerPool> pool_; 213 const scoped_refptr<SequencedWorkerPool> pool_;
(...skipping 23 matching lines...) Expand all
236 TimeDelta delay) { 237 TimeDelta delay) {
237 if (delay.is_zero()) { 238 if (delay.is_zero()) {
238 return pool_->PostSequencedWorkerTaskWithShutdownBehavior( 239 return pool_->PostSequencedWorkerTaskWithShutdownBehavior(
239 token_, from_here, std::move(task), shutdown_behavior_); 240 token_, from_here, std::move(task), shutdown_behavior_);
240 } 241 }
241 return pool_->PostDelayedSequencedWorkerTask(token_, from_here, 242 return pool_->PostDelayedSequencedWorkerTask(token_, from_here,
242 std::move(task), delay); 243 std::move(task), delay);
243 } 244 }
244 245
245 bool SequencedWorkerPool::PoolSequencedTaskRunner:: 246 bool SequencedWorkerPool::PoolSequencedTaskRunner::
246 RunsTasksOnCurrentThread() const { 247 RunsTasksInCurrentSequence() const {
247 return pool_->IsRunningSequenceOnCurrentThread(token_); 248 return pool_->IsRunningSequenceOnCurrentThread(token_);
248 } 249 }
249 250
250 bool SequencedWorkerPool::PoolSequencedTaskRunner::PostNonNestableDelayedTask( 251 bool SequencedWorkerPool::PoolSequencedTaskRunner::PostNonNestableDelayedTask(
251 const tracked_objects::Location& from_here, 252 const tracked_objects::Location& from_here,
252 OnceClosure task, 253 OnceClosure task,
253 TimeDelta delay) { 254 TimeDelta delay) {
254 // There's no way to run nested tasks, so simply forward to 255 // There's no way to run nested tasks, so simply forward to
255 // PostDelayedTask. 256 // PostDelayedTask.
256 return PostDelayedTask(from_here, std::move(task), delay); 257 return PostDelayedTask(from_here, std::move(task), delay);
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 std::move(task), TimeDelta()); 1609 std::move(task), TimeDelta());
1609 } 1610 }
1610 1611
1611 bool SequencedWorkerPool::PostDelayedTask( 1612 bool SequencedWorkerPool::PostDelayedTask(
1612 const tracked_objects::Location& from_here, 1613 const tracked_objects::Location& from_here,
1613 OnceClosure task, 1614 OnceClosure task,
1614 TimeDelta delay) { 1615 TimeDelta delay) {
1615 return PostDelayedWorkerTask(from_here, std::move(task), delay); 1616 return PostDelayedWorkerTask(from_here, std::move(task), delay);
1616 } 1617 }
1617 1618
1618 bool SequencedWorkerPool::RunsTasksOnCurrentThread() const { 1619 bool SequencedWorkerPool::RunsTasksInCurrentSequence() const {
1619 return inner_->RunsTasksOnCurrentThread(); 1620 return inner_->RunsTasksOnCurrentThread();
1620 } 1621 }
1621 1622
1622 void SequencedWorkerPool::FlushForTesting() { 1623 void SequencedWorkerPool::FlushForTesting() {
1623 DCHECK(!RunsTasksOnCurrentThread()); 1624 DCHECK(!RunsTasksOnCurrentThread());
1624 base::ThreadRestrictions::ScopedAllowWait allow_wait; 1625 base::ThreadRestrictions::ScopedAllowWait allow_wait;
1625 if (g_all_pools_state == AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER) { 1626 if (g_all_pools_state == AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER) {
1626 // TODO(gab): Remove this if http://crbug.com/622400 fails. 1627 // TODO(gab): Remove this if http://crbug.com/622400 fails.
1627 TaskScheduler::GetInstance()->FlushForTesting(); 1628 TaskScheduler::GetInstance()->FlushForTesting();
1628 } else { 1629 } else {
(...skipping 13 matching lines...) Expand all
1642 bool SequencedWorkerPool::IsShutdownInProgress() { 1643 bool SequencedWorkerPool::IsShutdownInProgress() {
1643 return inner_->IsShutdownInProgress(); 1644 return inner_->IsShutdownInProgress();
1644 } 1645 }
1645 1646
1646 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( 1647 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread(
1647 SequenceToken sequence_token) const { 1648 SequenceToken sequence_token) const {
1648 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); 1649 return inner_->IsRunningSequenceOnCurrentThread(sequence_token);
1649 } 1650 }
1650 1651
1651 } // namespace base 1652 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698