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

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: review:danakj#28 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/sequence.h » ('j') | no next file with comments »
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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // so long as |thread_pool| is alive. 71 // so long as |thread_pool| is alive.
72 // TODO(robliao): Find a concrete way to manage |thread_pool|'s memory. 72 // TODO(robliao): Find a concrete way to manage |thread_pool|'s memory.
73 SchedulerSequencedTaskRunner(const TaskTraits& traits, 73 SchedulerSequencedTaskRunner(const TaskTraits& traits,
74 SchedulerThreadPool* thread_pool) 74 SchedulerThreadPool* thread_pool)
75 : traits_(traits), thread_pool_(thread_pool) {} 75 : traits_(traits), thread_pool_(thread_pool) {}
76 76
77 // SequencedTaskRunner: 77 // SequencedTaskRunner:
78 bool PostDelayedTask(const tracked_objects::Location& from_here, 78 bool PostDelayedTask(const tracked_objects::Location& from_here,
79 const Closure& closure, 79 const Closure& closure,
80 TimeDelta delay) override { 80 TimeDelta delay) override {
81 std::unique_ptr<Task> task(new Task(from_here, closure, traits_, delay));
82 task->sequenced_task_runner_ref = this;
83
81 // Post the task as part of |sequence_|. 84 // Post the task as part of |sequence_|.
82 return thread_pool_->PostTaskWithSequence( 85 return thread_pool_->PostTaskWithSequence(std::move(task), sequence_,
83 WrapUnique(new Task(from_here, closure, traits_, delay)), sequence_, 86 nullptr);
84 nullptr);
85 } 87 }
86 88
87 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 89 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
88 const Closure& closure, 90 const Closure& closure,
89 base::TimeDelta delay) override { 91 base::TimeDelta delay) override {
90 // Tasks are never nested within the task scheduler. 92 // Tasks are never nested within the task scheduler.
91 return PostDelayedTask(from_here, closure, delay); 93 return PostDelayedTask(from_here, closure, delay);
92 } 94 }
93 95
94 bool RunsTasksOnCurrentThread() const override { 96 bool RunsTasksOnCurrentThread() const override {
(...skipping 23 matching lines...) Expand all
118 SchedulerThreadPool* thread_pool, 120 SchedulerThreadPool* thread_pool,
119 SchedulerWorkerThread* worker_thread) 121 SchedulerWorkerThread* worker_thread)
120 : traits_(traits), 122 : traits_(traits),
121 thread_pool_(thread_pool), 123 thread_pool_(thread_pool),
122 worker_thread_(worker_thread) {} 124 worker_thread_(worker_thread) {}
123 125
124 // SingleThreadTaskRunner: 126 // SingleThreadTaskRunner:
125 bool PostDelayedTask(const tracked_objects::Location& from_here, 127 bool PostDelayedTask(const tracked_objects::Location& from_here,
126 const Closure& closure, 128 const Closure& closure,
127 TimeDelta delay) override { 129 TimeDelta delay) override {
130 std::unique_ptr<Task> task(new Task(from_here, closure, traits_, delay));
131 task->single_thread_task_runner_ref = this;
132
128 // Post the task to be executed by |worker_thread_| as part of |sequence_|. 133 // Post the task to be executed by |worker_thread_| as part of |sequence_|.
129 return thread_pool_->PostTaskWithSequence( 134 return thread_pool_->PostTaskWithSequence(std::move(task), sequence_,
130 WrapUnique(new Task(from_here, closure, traits_, delay)), sequence_, 135 worker_thread_);
131 worker_thread_);
132 } 136 }
133 137
134 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 138 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
135 const Closure& closure, 139 const Closure& closure,
136 base::TimeDelta delay) override { 140 base::TimeDelta delay) override {
137 // Tasks are never nested within the task scheduler. 141 // Tasks are never nested within the task scheduler.
138 return PostDelayedTask(from_here, closure, delay); 142 return PostDelayedTask(from_here, closure, delay);
139 } 143 }
140 144
141 bool RunsTasksOnCurrentThread() const override { 145 bool RunsTasksOnCurrentThread() const override {
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 } 532 }
529 533
530 void SchedulerThreadPoolImpl::RemoveFromIdleWorkerThreadsStack( 534 void SchedulerThreadPoolImpl::RemoveFromIdleWorkerThreadsStack(
531 SchedulerWorkerThread* worker_thread) { 535 SchedulerWorkerThread* worker_thread) {
532 AutoSchedulerLock auto_lock(idle_worker_threads_stack_lock_); 536 AutoSchedulerLock auto_lock(idle_worker_threads_stack_lock_);
533 idle_worker_threads_stack_.Remove(worker_thread); 537 idle_worker_threads_stack_.Remove(worker_thread);
534 } 538 }
535 539
536 } // namespace internal 540 } // namespace internal
537 } // namespace base 541 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/task_scheduler/sequence.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698