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

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

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: s/base::ResetAndReturn/std::move/ Created 3 years, 9 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
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_worker_pool_impl.h" 5 #include "base/task_scheduler/scheduler_worker_pool_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // long as |worker_pool| is alive. 51 // long as |worker_pool| is alive.
52 // TODO(robliao): Find a concrete way to manage |worker_pool|'s memory. 52 // TODO(robliao): Find a concrete way to manage |worker_pool|'s memory.
53 SchedulerParallelTaskRunner(const TaskTraits& traits, 53 SchedulerParallelTaskRunner(const TaskTraits& traits,
54 SchedulerWorkerPool* worker_pool) 54 SchedulerWorkerPool* worker_pool)
55 : traits_(traits), worker_pool_(worker_pool) { 55 : traits_(traits), worker_pool_(worker_pool) {
56 DCHECK(worker_pool_); 56 DCHECK(worker_pool_);
57 } 57 }
58 58
59 // TaskRunner: 59 // TaskRunner:
60 bool PostDelayedTask(const tracked_objects::Location& from_here, 60 bool PostDelayedTask(const tracked_objects::Location& from_here,
61 const Closure& closure, 61 Closure closure,
62 TimeDelta delay) override { 62 TimeDelta delay) override {
63 // Post the task as part of a one-off single-task Sequence. 63 // Post the task as part of a one-off single-task Sequence.
64 return worker_pool_->PostTaskWithSequence( 64 return worker_pool_->PostTaskWithSequence(
65 MakeUnique<Task>(from_here, closure, traits_, delay), 65 MakeUnique<Task>(from_here, std::move(closure), traits_, delay),
66 make_scoped_refptr(new Sequence)); 66 make_scoped_refptr(new Sequence));
67 } 67 }
68 68
69 bool RunsTasksOnCurrentThread() const override { 69 bool RunsTasksOnCurrentThread() const override {
70 return tls_current_worker_pool.Get().Get() == worker_pool_; 70 return tls_current_worker_pool.Get().Get() == worker_pool_;
71 } 71 }
72 72
73 private: 73 private:
74 ~SchedulerParallelTaskRunner() override = default; 74 ~SchedulerParallelTaskRunner() override = default;
75 75
(...skipping 10 matching lines...) Expand all
86 // so long as |worker_pool| is alive. 86 // so long as |worker_pool| is alive.
87 // TODO(robliao): Find a concrete way to manage |worker_pool|'s memory. 87 // TODO(robliao): Find a concrete way to manage |worker_pool|'s memory.
88 SchedulerSequencedTaskRunner(const TaskTraits& traits, 88 SchedulerSequencedTaskRunner(const TaskTraits& traits,
89 SchedulerWorkerPool* worker_pool) 89 SchedulerWorkerPool* worker_pool)
90 : traits_(traits), worker_pool_(worker_pool) { 90 : traits_(traits), worker_pool_(worker_pool) {
91 DCHECK(worker_pool_); 91 DCHECK(worker_pool_);
92 } 92 }
93 93
94 // SequencedTaskRunner: 94 // SequencedTaskRunner:
95 bool PostDelayedTask(const tracked_objects::Location& from_here, 95 bool PostDelayedTask(const tracked_objects::Location& from_here,
96 const Closure& closure, 96 Closure closure,
97 TimeDelta delay) override { 97 TimeDelta delay) override {
98 std::unique_ptr<Task> task(new Task(from_here, closure, traits_, delay)); 98 std::unique_ptr<Task> task(
99 new Task(from_here, std::move(closure), traits_, delay));
99 task->sequenced_task_runner_ref = this; 100 task->sequenced_task_runner_ref = this;
100 101
101 // Post the task as part of |sequence_|. 102 // Post the task as part of |sequence_|.
102 return worker_pool_->PostTaskWithSequence(std::move(task), sequence_); 103 return worker_pool_->PostTaskWithSequence(std::move(task), sequence_);
103 } 104 }
104 105
105 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 106 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
106 const Closure& closure, 107 Closure closure,
107 base::TimeDelta delay) override { 108 base::TimeDelta delay) override {
108 // Tasks are never nested within the task scheduler. 109 // Tasks are never nested within the task scheduler.
109 return PostDelayedTask(from_here, closure, delay); 110 return PostDelayedTask(from_here, std::move(closure), delay);
110 } 111 }
111 112
112 bool RunsTasksOnCurrentThread() const override { 113 bool RunsTasksOnCurrentThread() const override {
113 // TODO(fdoray): Rename TaskRunner::RunsTaskOnCurrentThread() to something 114 // TODO(fdoray): Rename TaskRunner::RunsTaskOnCurrentThread() to something
114 // that reflects this behavior more accurately. crbug.com/646905 115 // that reflects this behavior more accurately. crbug.com/646905
115 return sequence_->token() == SequenceToken::GetForCurrentThread(); 116 return sequence_->token() == SequenceToken::GetForCurrentThread();
116 } 117 }
117 118
118 private: 119 private:
119 ~SchedulerSequencedTaskRunner() override = default; 120 ~SchedulerSequencedTaskRunner() override = default;
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); 586 AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
586 idle_workers_stack_.Remove(worker); 587 idle_workers_stack_.Remove(worker);
587 } 588 }
588 589
589 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { 590 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() {
590 return !worker_detachment_disallowed_.IsSet(); 591 return !worker_detachment_disallowed_.IsSet();
591 } 592 }
592 593
593 } // namespace internal 594 } // namespace internal
594 } // namespace base 595 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698