Commit 37151e94 authored by gab's avatar gab Committed by Commit bot

Disallow single-threaded SequencedWorkerPools.

BUG=646443

Review-Url: https://codereview.chromium.org/2330303003
Cr-Commit-Position: refs/heads/master@{#419496}
parent 03f3d50e
......@@ -652,7 +652,9 @@ SequencedWorkerPool::Inner::Inner(SequencedWorkerPool* worker_pool,
cleanup_idlers_(0),
cleanup_cv_(&lock_),
testing_observer_(observer),
task_priority_(task_priority) {}
task_priority_(task_priority) {
DCHECK_GT(max_threads_, 1U);
}
SequencedWorkerPool::Inner::~Inner() {
// You must call Shutdown() before destroying the pool.
......@@ -848,22 +850,6 @@ SequencedWorkerPool::Inner::GetTaskSchedulerTaskRunner(
if (!task_runner) {
ExecutionMode execution_mode =
sequence_token_id ? ExecutionMode::SEQUENCED : ExecutionMode::PARALLEL;
if (max_threads_ == 1U) {
// Tasks posted to single-threaded pools can assume thread affinity.
execution_mode = ExecutionMode::SINGLE_THREADED;
// Disallow posting tasks with different sequence tokens to single-
// threaded pools since the TaskScheduler can't force different sequences
// to run on the same thread.
DCHECK_LE(sequenced_task_runner_map_.size(), 1U);
// Disallow posting tasks without a sequence token to a single-threaded
// pool. No users do that currently and we don't want to support new use
// cases.
DCHECK(sequence_token_id);
}
task_runner = CreateTaskRunnerWithTraits(traits, execution_mode);
}
......
......@@ -180,8 +180,6 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner {
// Ideally, call this on the main thread of a process, before any other
// threads are created and before any tasks are posted to that process'
// SequencedWorkerPools.
// Note: SequencedWorkerPool instances with |max_threads == 1| will be special
// cased to send all of their work as ExecutionMode::SINGLE_THREADED.
// TODO(gab): Remove this if http://crbug.com/622400 fails
// (SequencedWorkerPool will be phased out completely otherwise).
static void RedirectToTaskSchedulerForProcess();
......@@ -198,11 +196,12 @@ class BASE_EXPORT SequencedWorkerPool : public TaskRunner {
// ThreadTaskRunnerHandle on the current thread unless you plan to
// deliberately leak it.
// Pass the maximum number of threads (they will be lazily created as needed)
// and a prefix for the thread name to aid in debugging. |task_priority| will
// be used to hint base::TaskScheduler for an experiment in which all
// SequencedWorkerPool tasks will be redirected to it in processes where a
// base::TaskScheduler was instantiated.
// Constructs a SequencedWorkerPool which will lazily create up to
// |max_threads| and a prefix for the thread name to aid in debugging.
// |max_threads| must be greater than 1. |task_priority| will be used to hint
// base::TaskScheduler for an experiment in which all SequencedWorkerPool
// tasks will be redirected to it in processes where a base::TaskScheduler was
// instantiated.
SequencedWorkerPool(size_t max_threads,
const std::string& thread_name_prefix,
base::TaskPriority task_priority);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment