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_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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // TaskRunner: | 59 // TaskRunner: |
60 bool PostDelayedTask(const tracked_objects::Location& from_here, | 60 bool PostDelayedTask(const tracked_objects::Location& from_here, |
61 OnceClosure closure, | 61 OnceClosure 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, std::move(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 RunsTasksInCurrentSequence() 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 |
76 const TaskTraits traits_; | 76 const TaskTraits traits_; |
77 SchedulerWorkerPool* const worker_pool_; | 77 SchedulerWorkerPool* const worker_pool_; |
78 | 78 |
79 DISALLOW_COPY_AND_ASSIGN(SchedulerParallelTaskRunner); | 79 DISALLOW_COPY_AND_ASSIGN(SchedulerParallelTaskRunner); |
(...skipping 23 matching lines...) Expand all Loading... |
103 return worker_pool_->PostTaskWithSequence(std::move(task), sequence_); | 103 return worker_pool_->PostTaskWithSequence(std::move(task), sequence_); |
104 } | 104 } |
105 | 105 |
106 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 106 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
107 OnceClosure closure, | 107 OnceClosure closure, |
108 base::TimeDelta delay) override { | 108 base::TimeDelta delay) override { |
109 // Tasks are never nested within the task scheduler. | 109 // Tasks are never nested within the task scheduler. |
110 return PostDelayedTask(from_here, std::move(closure), delay); | 110 return PostDelayedTask(from_here, std::move(closure), delay); |
111 } | 111 } |
112 | 112 |
113 bool RunsTasksOnCurrentThread() const override { | 113 bool RunsTasksInCurrentSequence() const override { |
114 // TODO(fdoray): Rename TaskRunner::RunsTaskOnCurrentThread() to something | |
115 // that reflects this behavior more accurately. crbug.com/646905 | |
116 return sequence_->token() == SequenceToken::GetForCurrentThread(); | 114 return sequence_->token() == SequenceToken::GetForCurrentThread(); |
117 } | 115 } |
118 | 116 |
119 private: | 117 private: |
120 ~SchedulerSequencedTaskRunner() override = default; | 118 ~SchedulerSequencedTaskRunner() override = default; |
121 | 119 |
122 // Sequence for all Tasks posted through this TaskRunner. | 120 // Sequence for all Tasks posted through this TaskRunner. |
123 const scoped_refptr<Sequence> sequence_ = new Sequence; | 121 const scoped_refptr<Sequence> sequence_ = new Sequence; |
124 | 122 |
125 const TaskTraits traits_; | 123 const TaskTraits traits_; |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); | 614 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); |
617 idle_workers_stack_.Remove(worker); | 615 idle_workers_stack_.Remove(worker); |
618 } | 616 } |
619 | 617 |
620 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { | 618 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { |
621 return !worker_detachment_disallowed_.IsSet(); | 619 return !worker_detachment_disallowed_.IsSet(); |
622 } | 620 } |
623 | 621 |
624 } // namespace internal | 622 } // namespace internal |
625 } // namespace base | 623 } // namespace base |
OLD | NEW |