Chromium Code Reviews| 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.h" | 5 #include "base/task_scheduler/scheduler_thread_pool.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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 class SchedulerThreadPool::SchedulerWorkerThreadDelegateImpl | 124 class SchedulerThreadPool::SchedulerWorkerThreadDelegateImpl |
| 125 : public SchedulerWorkerThread::Delegate { | 125 : public SchedulerWorkerThread::Delegate { |
| 126 public: | 126 public: |
| 127 SchedulerWorkerThreadDelegateImpl( | 127 SchedulerWorkerThreadDelegateImpl( |
| 128 SchedulerThreadPool* outer, | 128 SchedulerThreadPool* outer, |
| 129 const EnqueueSequenceCallback& enqueue_sequence_callback); | 129 const EnqueueSequenceCallback& enqueue_sequence_callback); |
| 130 ~SchedulerWorkerThreadDelegateImpl() override; | 130 ~SchedulerWorkerThreadDelegateImpl() override; |
| 131 | 131 |
| 132 // SchedulerWorkerThread::Delegate: | 132 // SchedulerWorkerThread::Delegate: |
| 133 void OnMainEntry() override; | 133 void OnMainEntry() override; |
| 134 scoped_refptr<Sequence> GetWork( | 134 scoped_refptr<Sequence> GetWork(SchedulerWorkerThread* worker_thread, |
| 135 SchedulerWorkerThread* worker_thread) override; | 135 PriorityQueue* alternate_priority_queue, |
| 136 bool* alternate_priority_queue_used) override; | |
| 136 void EnqueueSequence(scoped_refptr<Sequence> sequence) override; | 137 void EnqueueSequence(scoped_refptr<Sequence> sequence) override; |
| 137 | 138 |
| 138 private: | 139 private: |
| 139 SchedulerThreadPool* outer_; | 140 SchedulerThreadPool* outer_; |
| 140 const EnqueueSequenceCallback enqueue_sequence_callback_; | 141 const EnqueueSequenceCallback enqueue_sequence_callback_; |
| 141 | 142 |
| 142 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerThreadDelegateImpl); | 143 DISALLOW_COPY_AND_ASSIGN(SchedulerWorkerThreadDelegateImpl); |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 SchedulerThreadPool::~SchedulerThreadPool() { | 146 SchedulerThreadPool::~SchedulerThreadPool() { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 SchedulerThreadPool::SchedulerWorkerThreadDelegateImpl:: | 241 SchedulerThreadPool::SchedulerWorkerThreadDelegateImpl:: |
| 241 ~SchedulerWorkerThreadDelegateImpl() = default; | 242 ~SchedulerWorkerThreadDelegateImpl() = default; |
| 242 | 243 |
| 243 void SchedulerThreadPool::SchedulerWorkerThreadDelegateImpl::OnMainEntry() { | 244 void SchedulerThreadPool::SchedulerWorkerThreadDelegateImpl::OnMainEntry() { |
| 244 DCHECK(!tls_current_thread_pool.Get().Get()); | 245 DCHECK(!tls_current_thread_pool.Get().Get()); |
| 245 tls_current_thread_pool.Get().Set(outer_); | 246 tls_current_thread_pool.Get().Set(outer_); |
| 246 } | 247 } |
| 247 | 248 |
| 248 scoped_refptr<Sequence> | 249 scoped_refptr<Sequence> |
| 249 SchedulerThreadPool::SchedulerWorkerThreadDelegateImpl::GetWork( | 250 SchedulerThreadPool::SchedulerWorkerThreadDelegateImpl::GetWork( |
| 250 SchedulerWorkerThread* worker_thread) { | 251 SchedulerWorkerThread* worker_thread, |
| 252 PriorityQueue* alternate_priority_queue, | |
|
danakj
2016/04/20 23:16:16
I would not add these arguments until you're going
fdoray
2016/04/21 19:31:28
n/a with the latest patch set
| |
| 253 bool* alternate_priority_queue_used) { | |
| 254 // TODO(fdoray): Return a Sequence from |alternate_priority_queue| when | |
| 255 // appropriate. | |
| 256 | |
| 251 std::unique_ptr<PriorityQueue::Transaction> transaction( | 257 std::unique_ptr<PriorityQueue::Transaction> transaction( |
| 252 outer_->shared_priority_queue_.BeginTransaction()); | 258 outer_->shared_priority_queue_.BeginTransaction()); |
| 253 const auto& sequence_and_sort_key = transaction->Peek(); | 259 const auto& sequence_and_sort_key = transaction->Peek(); |
| 254 | 260 |
| 255 if (sequence_and_sort_key.is_null()) { | 261 if (sequence_and_sort_key.is_null()) { |
| 256 // |transaction| is kept alive while |worker_thread| is added to | 262 // |transaction| is kept alive while |worker_thread| is added to |
| 257 // |idle_worker_threads_stack_| to avoid this race: | 263 // |idle_worker_threads_stack_| to avoid this race: |
| 258 // 1. This thread creates a Transaction, finds |shared_priority_queue_| | 264 // 1. This thread creates a Transaction, finds |shared_priority_queue_| |
| 259 // empty and ends the Transaction. | 265 // empty and ends the Transaction. |
| 260 // 2. Other thread creates a Transaction, inserts a Sequence into | 266 // 2. Other thread creates a Transaction, inserts a Sequence into |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 | 304 |
| 299 bool SchedulerThreadPool::Initialize(ThreadPriority thread_priority, | 305 bool SchedulerThreadPool::Initialize(ThreadPriority thread_priority, |
| 300 size_t max_threads) { | 306 size_t max_threads) { |
| 301 AutoSchedulerLock auto_lock(idle_worker_threads_stack_lock_); | 307 AutoSchedulerLock auto_lock(idle_worker_threads_stack_lock_); |
| 302 | 308 |
| 303 DCHECK(worker_threads_.empty()); | 309 DCHECK(worker_threads_.empty()); |
| 304 | 310 |
| 305 for (size_t i = 0; i < max_threads; ++i) { | 311 for (size_t i = 0; i < max_threads; ++i) { |
| 306 std::unique_ptr<SchedulerWorkerThread> worker_thread = | 312 std::unique_ptr<SchedulerWorkerThread> worker_thread = |
| 307 SchedulerWorkerThread::CreateSchedulerWorkerThread( | 313 SchedulerWorkerThread::CreateSchedulerWorkerThread( |
| 308 thread_priority, worker_thread_delegate_.get(), task_tracker_); | 314 thread_priority, worker_thread_delegate_.get(), task_tracker_, |
| 315 delayed_task_manager_, &shared_priority_queue_); | |
| 309 if (!worker_thread) | 316 if (!worker_thread) |
| 310 break; | 317 break; |
| 311 idle_worker_threads_stack_.push(worker_thread.get()); | 318 idle_worker_threads_stack_.push(worker_thread.get()); |
| 312 worker_threads_.push_back(std::move(worker_thread)); | 319 worker_threads_.push_back(std::move(worker_thread)); |
| 313 } | 320 } |
| 314 | 321 |
| 315 return !worker_threads_.empty(); | 322 return !worker_threads_.empty(); |
| 316 } | 323 } |
| 317 | 324 |
| 318 void SchedulerThreadPool::WakeUpOneThread() { | 325 void SchedulerThreadPool::WakeUpOneThread() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 337 if (idle_worker_threads_stack_.empty()) | 344 if (idle_worker_threads_stack_.empty()) |
| 338 return nullptr; | 345 return nullptr; |
| 339 | 346 |
| 340 auto worker_thread = idle_worker_threads_stack_.top(); | 347 auto worker_thread = idle_worker_threads_stack_.top(); |
| 341 idle_worker_threads_stack_.pop(); | 348 idle_worker_threads_stack_.pop(); |
| 342 return worker_thread; | 349 return worker_thread; |
| 343 } | 350 } |
| 344 | 351 |
| 345 } // namespace internal | 352 } // namespace internal |
| 346 } // namespace base | 353 } // namespace base |
| OLD | NEW |