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

Side by Side Diff: base/task_scheduler/scheduler_thread_pool_impl.cc

Issue 1911023002: TaskScheduler: Add TaskRunnerHandle support to TaskScheduler tasks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@c1_1876363004_STTR
Patch Set: rebase and more test logic in TestTaskFactory to cover SchedulerThreadPoolImpl changes Created 4 years, 7 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 | base/task_scheduler/task.h » ('j') | base/task_scheduler/task.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/task_scheduler/scheduler_thread_pool_impl.h" 5 #include "base/task_scheduler/scheduler_thread_pool_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // so long as |thread_pool| is alive. 70 // so long as |thread_pool| is alive.
71 // TODO(robliao): Find a concrete way to manage |thread_pool|'s memory. 71 // TODO(robliao): Find a concrete way to manage |thread_pool|'s memory.
72 SchedulerSequencedTaskRunner(const TaskTraits& traits, 72 SchedulerSequencedTaskRunner(const TaskTraits& traits,
73 SchedulerThreadPool* thread_pool) 73 SchedulerThreadPool* thread_pool)
74 : traits_(traits), thread_pool_(thread_pool) {} 74 : traits_(traits), thread_pool_(thread_pool) {}
75 75
76 // SequencedTaskRunner: 76 // SequencedTaskRunner:
77 bool PostDelayedTask(const tracked_objects::Location& from_here, 77 bool PostDelayedTask(const tracked_objects::Location& from_here,
78 const Closure& closure, 78 const Closure& closure,
79 TimeDelta delay) override { 79 TimeDelta delay) override {
80 std::unique_ptr<Task> task(new Task(from_here, closure, traits_, delay));
81 task->sequenced_task_runner_ref = this;
82
80 // Post the task as part of |sequence_|. 83 // Post the task as part of |sequence_|.
81 return thread_pool_->PostTaskWithSequence( 84 return thread_pool_->PostTaskWithSequence(std::move(task), sequence_,
82 WrapUnique(new Task(from_here, closure, traits_, delay)), sequence_, 85 nullptr);
83 nullptr);
84 } 86 }
85 87
86 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 88 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
87 const Closure& closure, 89 const Closure& closure,
88 base::TimeDelta delay) override { 90 base::TimeDelta delay) override {
89 // Tasks are never nested within the task scheduler. 91 // Tasks are never nested within the task scheduler.
90 return PostDelayedTask(from_here, closure, delay); 92 return PostDelayedTask(from_here, closure, delay);
91 } 93 }
92 94
93 bool RunsTasksOnCurrentThread() const override { 95 bool RunsTasksOnCurrentThread() const override {
(...skipping 23 matching lines...) Expand all
117 SchedulerThreadPool* thread_pool, 119 SchedulerThreadPool* thread_pool,
118 SchedulerWorkerThread* worker_thread) 120 SchedulerWorkerThread* worker_thread)
119 : traits_(traits), 121 : traits_(traits),
120 thread_pool_(thread_pool), 122 thread_pool_(thread_pool),
121 worker_thread_(worker_thread) {} 123 worker_thread_(worker_thread) {}
122 124
123 // SingleThreadTaskRunner: 125 // SingleThreadTaskRunner:
124 bool PostDelayedTask(const tracked_objects::Location& from_here, 126 bool PostDelayedTask(const tracked_objects::Location& from_here,
125 const Closure& closure, 127 const Closure& closure,
126 TimeDelta delay) override { 128 TimeDelta delay) override {
129 std::unique_ptr<Task> task(new Task(from_here, closure, traits_, delay));
130 task->single_thread_task_runner_ref = this;
131
127 // Post the task to be executed by |worker_thread_| as part of |sequence_|. 132 // Post the task to be executed by |worker_thread_| as part of |sequence_|.
128 return thread_pool_->PostTaskWithSequence( 133 return thread_pool_->PostTaskWithSequence(std::move(task), sequence_,
129 WrapUnique(new Task(from_here, closure, traits_, delay)), sequence_, 134 worker_thread_);
130 worker_thread_);
131 } 135 }
132 136
133 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 137 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
134 const Closure& closure, 138 const Closure& closure,
135 base::TimeDelta delay) override { 139 base::TimeDelta delay) override {
136 // Tasks are never nested within the task scheduler. 140 // Tasks are never nested within the task scheduler.
137 return PostDelayedTask(from_here, closure, delay); 141 return PostDelayedTask(from_here, closure, delay);
138 } 142 }
139 143
140 bool RunsTasksOnCurrentThread() const override { 144 bool RunsTasksOnCurrentThread() const override {
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 } 515 }
512 516
513 void SchedulerThreadPoolImpl::RemoveFromIdleWorkerThreadsStack( 517 void SchedulerThreadPoolImpl::RemoveFromIdleWorkerThreadsStack(
514 SchedulerWorkerThread* worker_thread) { 518 SchedulerWorkerThread* worker_thread) {
515 AutoSchedulerLock auto_lock(idle_worker_threads_stack_lock_); 519 AutoSchedulerLock auto_lock(idle_worker_threads_stack_lock_);
516 idle_worker_threads_stack_.Remove(worker_thread); 520 idle_worker_threads_stack_.Remove(worker_thread);
517 } 521 }
518 522
519 } // namespace internal 523 } // namespace internal
520 } // namespace base 524 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/task_scheduler/task.h » ('j') | base/task_scheduler/task.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698