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

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

Issue 2330303003: Disallow single-threaded SequencedWorkerPools. (Closed)
Patch Set: merge up to r419443 Created 4 years, 3 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 | « base/threading/sequenced_worker_pool.h ('k') | no next file » | no next file with comments »
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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 blocking_shutdown_thread_count_(0), 645 blocking_shutdown_thread_count_(0),
646 next_sequence_task_number_(0), 646 next_sequence_task_number_(0),
647 blocking_shutdown_pending_task_count_(0), 647 blocking_shutdown_pending_task_count_(0),
648 trace_id_(0), 648 trace_id_(0),
649 shutdown_called_(false), 649 shutdown_called_(false),
650 max_blocking_tasks_after_shutdown_(0), 650 max_blocking_tasks_after_shutdown_(0),
651 cleanup_state_(CLEANUP_DONE), 651 cleanup_state_(CLEANUP_DONE),
652 cleanup_idlers_(0), 652 cleanup_idlers_(0),
653 cleanup_cv_(&lock_), 653 cleanup_cv_(&lock_),
654 testing_observer_(observer), 654 testing_observer_(observer),
655 task_priority_(task_priority) {} 655 task_priority_(task_priority) {
656 DCHECK_GT(max_threads_, 1U);
657 }
656 658
657 SequencedWorkerPool::Inner::~Inner() { 659 SequencedWorkerPool::Inner::~Inner() {
658 // You must call Shutdown() before destroying the pool. 660 // You must call Shutdown() before destroying the pool.
659 DCHECK(shutdown_called_); 661 DCHECK(shutdown_called_);
660 662
661 // Need to explicitly join with the threads before they're destroyed or else 663 // Need to explicitly join with the threads before they're destroyed or else
662 // they will be running when our object is half torn down. 664 // they will be running when our object is half torn down.
663 for (ThreadMap::iterator it = threads_.begin(); it != threads_.end(); ++it) 665 for (ThreadMap::iterator it = threads_.begin(); it != threads_.end(); ++it)
664 it->second->Join(); 666 it->second->Join();
665 threads_.clear(); 667 threads_.clear();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 sequence_token_id ? sequenced_task_runner_map_[sequence_token_id] 843 sequence_token_id ? sequenced_task_runner_map_[sequence_token_id]
842 : unsequenced_task_runners_[static_cast<int>( 844 : unsequenced_task_runners_[static_cast<int>(
843 traits.shutdown_behavior())]; 845 traits.shutdown_behavior())];
844 846
845 // TODO(fdoray): DCHECK that all tasks posted to the same sequence have the 847 // TODO(fdoray): DCHECK that all tasks posted to the same sequence have the
846 // same shutdown behavior. 848 // same shutdown behavior.
847 849
848 if (!task_runner) { 850 if (!task_runner) {
849 ExecutionMode execution_mode = 851 ExecutionMode execution_mode =
850 sequence_token_id ? ExecutionMode::SEQUENCED : ExecutionMode::PARALLEL; 852 sequence_token_id ? ExecutionMode::SEQUENCED : ExecutionMode::PARALLEL;
851
852 if (max_threads_ == 1U) {
853 // Tasks posted to single-threaded pools can assume thread affinity.
854 execution_mode = ExecutionMode::SINGLE_THREADED;
855
856 // Disallow posting tasks with different sequence tokens to single-
857 // threaded pools since the TaskScheduler can't force different sequences
858 // to run on the same thread.
859 DCHECK_LE(sequenced_task_runner_map_.size(), 1U);
860
861 // Disallow posting tasks without a sequence token to a single-threaded
862 // pool. No users do that currently and we don't want to support new use
863 // cases.
864 DCHECK(sequence_token_id);
865 }
866
867 task_runner = CreateTaskRunnerWithTraits(traits, execution_mode); 853 task_runner = CreateTaskRunnerWithTraits(traits, execution_mode);
868 } 854 }
869 855
870 return task_runner; 856 return task_runner;
871 } 857 }
872 858
873 bool SequencedWorkerPool::Inner::RunsTasksOnCurrentThread() const { 859 bool SequencedWorkerPool::Inner::RunsTasksOnCurrentThread() const {
874 AutoLock lock(lock_); 860 AutoLock lock(lock_);
875 if (subtle::NoBarrier_Load(&g_all_pools_state) == 861 if (subtle::NoBarrier_Load(&g_all_pools_state) ==
876 AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER) { 862 AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER) {
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 bool SequencedWorkerPool::IsShutdownInProgress() { 1613 bool SequencedWorkerPool::IsShutdownInProgress() {
1628 return inner_->IsShutdownInProgress(); 1614 return inner_->IsShutdownInProgress();
1629 } 1615 }
1630 1616
1631 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread( 1617 bool SequencedWorkerPool::IsRunningSequenceOnCurrentThread(
1632 SequenceToken sequence_token) const { 1618 SequenceToken sequence_token) const {
1633 return inner_->IsRunningSequenceOnCurrentThread(sequence_token); 1619 return inner_->IsRunningSequenceOnCurrentThread(sequence_token);
1634 } 1620 }
1635 1621
1636 } // namespace base 1622 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/sequenced_worker_pool.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698