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

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: Comments 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 a non-leaky base::Singleton because they are generally
252 // destroyed before the process terminates via an AtExitManager
253 // registration. This will trigger a DCHECK to warn of such cases. See the
254 // comment about CONTINUE_ON_SHUTDOWN for more details.
255 ThreadRestrictions::SetSingletonAllowed(task_shutdown_behavior_ !=
256 CONTINUE_ON_SHUTDOWN);
249 } 257 }
250 258
251 // Indicates that the task has finished running. 259 // Indicates that the task has finished running.
252 void reset_running_task_info() { is_processing_task_ = false; } 260 void reset_running_task_info() { is_processing_task_ = false; }
253 261
254 // Whether the worker is processing a task. 262 // Whether the worker is processing a task.
255 bool is_processing_task() { return is_processing_task_; } 263 bool is_processing_task() { return is_processing_task_; }
256 264
257 SequenceToken task_sequence_token() const { 265 SequenceToken task_sequence_token() const {
258 DCHECK(is_processing_task_); 266 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) { 1404 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) {
1397 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); 1405 DCHECK(constructor_task_runner_->BelongsToCurrentThread());
1398 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); 1406 inner_->Shutdown(max_new_blocking_tasks_after_shutdown);
1399 } 1407 }
1400 1408
1401 bool SequencedWorkerPool::IsShutdownInProgress() { 1409 bool SequencedWorkerPool::IsShutdownInProgress() {
1402 return inner_->IsShutdownInProgress(); 1410 return inner_->IsShutdownInProgress();
1403 } 1411 }
1404 1412
1405 } // namespace base 1413 } // 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