OLD | NEW |
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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 // Gets the worker for the current thread out of thread-local storage. | 240 // Gets the worker for the current thread out of thread-local storage. |
241 static Worker* GetForCurrentThread(); | 241 static Worker* GetForCurrentThread(); |
242 | 242 |
243 // Indicates that a task is about to be run. The parameters provide | 243 // Indicates that a task is about to be run. The parameters provide |
244 // additional metainformation about the task being run. | 244 // additional metainformation about the task being run. |
245 void set_running_task_info(SequenceToken token, | 245 void set_running_task_info(SequenceToken token, |
246 WorkerShutdown shutdown_behavior) { | 246 WorkerShutdown shutdown_behavior) { |
247 is_processing_task_ = true; | 247 is_processing_task_ = true; |
248 task_sequence_token_ = token; | 248 task_sequence_token_ = token; |
249 task_shutdown_behavior_ = shutdown_behavior; | 249 task_shutdown_behavior_ = shutdown_behavior; |
| 250 |
| 251 // It is dangerous for tasks with CONTINUE_ON_SHUTDOWN to access a class |
| 252 // that implements a non-leaky base::Singleton because they are generally |
| 253 // destroyed before the process terminates via an AtExitManager |
| 254 // registration. This will trigger a DCHECK to warn of such cases. See the |
| 255 // comment about CONTINUE_ON_SHUTDOWN for more details. |
| 256 ThreadRestrictions::SetSingletonAllowed(task_shutdown_behavior_ != |
| 257 CONTINUE_ON_SHUTDOWN); |
250 } | 258 } |
251 | 259 |
252 // Indicates that the task has finished running. | 260 // Indicates that the task has finished running. |
253 void reset_running_task_info() { is_processing_task_ = false; } | 261 void reset_running_task_info() { is_processing_task_ = false; } |
254 | 262 |
255 // Whether the worker is processing a task. | 263 // Whether the worker is processing a task. |
256 bool is_processing_task() { return is_processing_task_; } | 264 bool is_processing_task() { return is_processing_task_; } |
257 | 265 |
258 SequenceToken task_sequence_token() const { | 266 SequenceToken task_sequence_token() const { |
259 DCHECK(is_processing_task_); | 267 DCHECK(is_processing_task_); |
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { | 1407 void SequencedWorkerPool::Shutdown(int max_new_blocking_tasks_after_shutdown) { |
1400 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); | 1408 DCHECK(constructor_task_runner_->BelongsToCurrentThread()); |
1401 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); | 1409 inner_->Shutdown(max_new_blocking_tasks_after_shutdown); |
1402 } | 1410 } |
1403 | 1411 |
1404 bool SequencedWorkerPool::IsShutdownInProgress() { | 1412 bool SequencedWorkerPool::IsShutdownInProgress() { |
1405 return inner_->IsShutdownInProgress(); | 1413 return inner_->IsShutdownInProgress(); |
1406 } | 1414 } |
1407 | 1415 |
1408 } // namespace base | 1416 } // namespace base |
OLD | NEW |