OLD | NEW |
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 Loading... |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |