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

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

Issue 1904273002: Enforce singleton not allowed behavior for CONTINUE_ON_SHUTDOWN tasks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | net/proxy/dhcpcsvc_init_win.cc » ('j') | net/proxy/dhcpcsvc_init_win.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 // Gets the worker for the current thread out of thread-local storage. 239 // Gets the worker for the current thread out of thread-local storage.
240 static Worker* GetForCurrentThread(); 240 static Worker* GetForCurrentThread();
241 241
242 // Indicates that a task is about to be run. The parameters provide 242 // Indicates that a task is about to be run. The parameters provide
243 // additional metainformation about the task being run. 243 // additional metainformation about the task being run.
244 void set_running_task_info(SequenceToken token, 244 void set_running_task_info(SequenceToken token,
245 WorkerShutdown shutdown_behavior) { 245 WorkerShutdown shutdown_behavior) {
246 is_processing_task_ = true; 246 is_processing_task_ = true;
247 task_sequence_token_ = token; 247 task_sequence_token_ = token;
248 task_shutdown_behavior_ = shutdown_behavior; 248 task_shutdown_behavior_ = shutdown_behavior;
249
250 // It is dangerous for tasks with CONTINUE_ON_SHUTDOWN to access a class
251 // that implements base::Singleton. This will trigger a DCHECK to warn of
robliao 2016/04/25 23:03:30 Put why this is the case in the comment as well. (
manzagop (departed) 2016/04/26 13:13:44 Also mention leaky versions are fine to access fro
Patrick Monette 2016/04/26 19:05:27 Done.
Patrick Monette 2016/04/26 19:05:27 Done.
252 // such cases. See the comment about CONTINUE_ON_SHUTDOWN for more details.
253 ThreadRestrictions::SetSingletonAllowed(task_shutdown_behavior_ !=
254 CONTINUE_ON_SHUTDOWN);
249 } 255 }
250 256
251 // Indicates that the task has finished running. 257 // Indicates that the task has finished running.
252 void reset_running_task_info() { is_processing_task_ = false; } 258 void reset_running_task_info() { is_processing_task_ = false; }
253 259
254 // Whether the worker is processing a task. 260 // Whether the worker is processing a task.
255 bool is_processing_task() { return is_processing_task_; } 261 bool is_processing_task() { return is_processing_task_; }
256 262
257 SequenceToken task_sequence_token() const { 263 SequenceToken task_sequence_token() const {
258 DCHECK(is_processing_task_); 264 DCHECK(is_processing_task_);
(...skipping 1137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { 1402 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) {
1397 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); 1403 DCHECK(constructor_task_runner_->BelongsToCurrentThread());
1398 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); 1404 inner_->Shutdown(max_new_blocking_tasks_after_shutdown);
1399 } 1405 }
1400 1406
1401 bool SequencedWorkerPool::IsShutdownInProgress() { 1407 bool SequencedWorkerPool::IsShutdownInProgress() {
1402 return inner_->IsShutdownInProgress(); 1408 return inner_->IsShutdownInProgress();
1403 } 1409 }
1404 1410
1405 } // namespace base 1411 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | net/proxy/dhcpcsvc_init_win.cc » ('j') | net/proxy/dhcpcsvc_init_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698