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

Unified Diff: base/threading/sequenced_worker_pool.cc

Issue 2285633003: Test SequencedWorkerPool with redirection to the TaskScheduler. (Closed)
Patch Set: Rewrote everything 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 side-by-side diff with in-line comments
Download patch
Index: base/threading/sequenced_worker_pool.cc
diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc
index ed6f411e4b8a809c2836b1b1990a3344eecb1c36..bd1b502f8f1b6e02914597cb9a68f4dfcec9f362 100644
--- a/base/threading/sequenced_worker_pool.cc
+++ b/base/threading/sequenced_worker_pool.cc
@@ -54,12 +54,16 @@ namespace base {
namespace {
-// An enum representing the state of all pools. Any given process should only
-// ever transition from NONE_ACTIVE to the active states, transitions between
-// actives states are unexpected. The REDIRECTED_TO_TASK_SCHEDULER transition
-// occurs when RedirectSequencedWorkerPoolsToTaskSchedulerForProcess() is called
-// and the WORKER_CREATED transition occurs when a Worker needs to be created
-// because the first task was posted and the state is still NONE_ACTIVE.
+// An enum representing the state of all pools. Any given non-test process
+// should only ever transition from NONE_ACTIVE to the active states,
danakj 2016/09/16 20:29:36 to one of the active states. Transitions between a
fdoray 2016/09/16 21:21:31 Done.
+// transitions between actives states are unexpected. The
+// REDIRECTED_TO_TASK_SCHEDULER transition occurs when
+// RedirectToTaskSchedulerForProcess() is called. The WORKER_CREATED transition
+// occurs when a Worker needs to be created because the first task was posted
+// and the state is still NONE_ACTIVE. In a test process, a transition to
+// NONE_ACTIVE occurs when ResetRedirectToTaskSchedulerForProcessForTesting() is
+// called.
+//
// |g_all_pools_state| uses relaxed atomic operations to ensure no data race
// between reads/writes, strict memory ordering isn't required per no other
// state being inferred from its value. Explicit synchronization (e.g. locks or
@@ -67,6 +71,7 @@ namespace {
// NONE_ACTIVE after the first Worker was created -- this is not possible for
// REDIRECTED_TO_TASK_SCHEDULER per its API requesting to be invoked while no
// other threads are active).
+//
// TODO(gab): Remove this if http://crbug.com/622400 fails (SequencedWorkerPool
// will be phased out completely otherwise).
enum AllPoolsState : subtle::Atomic32 {
@@ -902,6 +907,8 @@ bool SequencedWorkerPool::Inner::IsRunningSequenceOnCurrentThread(
// See https://code.google.com/p/chromium/issues/detail?id=168415
void SequencedWorkerPool::Inner::CleanupForTesting() {
+ DCHECK_NE(subtle::NoBarrier_Load(&g_all_pools_state),
+ AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER);
DCHECK(!RunsTasksOnCurrentThread());
base::ThreadRestrictions::ScopedAllowWait allow_wait;
AutoLock lock(lock_);
@@ -1449,8 +1456,7 @@ SequencedWorkerPool::GetWorkerPoolForCurrentThread() {
}
// static
-void SequencedWorkerPool::
- RedirectSequencedWorkerPoolsToTaskSchedulerForProcess() {
+void SequencedWorkerPool::RedirectToTaskSchedulerForProcess() {
DCHECK(TaskScheduler::GetInstance());
// Hitting this DCHECK indicates that a task was posted to a
// SequencedWorkerPool before the TaskScheduler was initialized and
@@ -1462,6 +1468,15 @@ void SequencedWorkerPool::
AllPoolsState::REDIRECTED_TO_TASK_SCHEDULER);
}
+// static
+void SequencedWorkerPool::ResetRedirectToTaskSchedulerForProcessForTesting() {
+ // This can be called when the current state is REDIRECTED_TO_TASK_SCHEDULER
+ // to stop redirecting tasks. It can also be called when the current state is
+ // WORKER_CREATED to allow RedirectToTaskSchedulerForProcess() to be called
+ // (can usually not be called after a worker has been created).
gab 2016/09/16 20:16:10 "when current state is WORKER_CREATED" and "usuall
fdoray 2016/09/16 21:21:31 Made the comment clearer.
+ subtle::NoBarrier_Store(&g_all_pools_state, AllPoolsState::NONE_ACTIVE);
+}
+
SequencedWorkerPool::SequencedWorkerPool(size_t max_threads,
const std::string& thread_name_prefix,
base::TaskPriority task_priority)

Powered by Google App Engine
This is Rietveld 408576698