| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 PriorityQueue* single_threaded_priority_queue() { | 196 PriorityQueue* single_threaded_priority_queue() { |
| 197 return &single_threaded_priority_queue_; | 197 return &single_threaded_priority_queue_; |
| 198 } | 198 } |
| 199 | 199 |
| 200 // SchedulerWorkerThread::Delegate: | 200 // SchedulerWorkerThread::Delegate: |
| 201 void OnMainEntry(SchedulerWorkerThread* worker_thread) override; | 201 void OnMainEntry(SchedulerWorkerThread* worker_thread) override; |
| 202 scoped_refptr<Sequence> GetWork( | 202 scoped_refptr<Sequence> GetWork( |
| 203 SchedulerWorkerThread* worker_thread) override; | 203 SchedulerWorkerThread* worker_thread) override; |
| 204 void ReEnqueueSequence(scoped_refptr<Sequence> sequence) override; | 204 void ReEnqueueSequence(scoped_refptr<Sequence> sequence) override; |
| 205 TimeDelta GetSleepTimeout() override; | 205 TimeDelta GetSleepTimeout() override; |
| 206 bool CanDetach(SchedulerWorkerThread* worker_thread) override; |
| 206 | 207 |
| 207 private: | 208 private: |
| 208 SchedulerThreadPoolImpl* outer_; | 209 SchedulerThreadPoolImpl* outer_; |
| 209 const ReEnqueueSequenceCallback re_enqueue_sequence_callback_; | 210 const ReEnqueueSequenceCallback re_enqueue_sequence_callback_; |
| 210 | 211 |
| 211 // Single-threaded PriorityQueue for the worker thread. | 212 // Single-threaded PriorityQueue for the worker thread. |
| 212 PriorityQueue single_threaded_priority_queue_; | 213 PriorityQueue single_threaded_priority_queue_; |
| 213 | 214 |
| 214 // True if the last Sequence returned by GetWork() was extracted from | 215 // True if the last Sequence returned by GetWork() was extracted from |
| 215 // |single_threaded_priority_queue_|. | 216 // |single_threaded_priority_queue_|. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 // |sequence| must be enqueued. | 479 // |sequence| must be enqueued. |
| 479 re_enqueue_sequence_callback_.Run(std::move(sequence)); | 480 re_enqueue_sequence_callback_.Run(std::move(sequence)); |
| 480 } | 481 } |
| 481 } | 482 } |
| 482 | 483 |
| 483 TimeDelta SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl:: | 484 TimeDelta SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl:: |
| 484 GetSleepTimeout() { | 485 GetSleepTimeout() { |
| 485 return TimeDelta::Max(); | 486 return TimeDelta::Max(); |
| 486 } | 487 } |
| 487 | 488 |
| 489 bool SchedulerThreadPoolImpl::SchedulerWorkerThreadDelegateImpl::CanDetach( |
| 490 SchedulerWorkerThread* worker_thread) { |
| 491 return false; |
| 492 } |
| 493 |
| 488 SchedulerThreadPoolImpl::SchedulerThreadPoolImpl( | 494 SchedulerThreadPoolImpl::SchedulerThreadPoolImpl( |
| 489 StringPiece name, | 495 StringPiece name, |
| 490 IORestriction io_restriction, | 496 IORestriction io_restriction, |
| 491 TaskTracker* task_tracker, | 497 TaskTracker* task_tracker, |
| 492 DelayedTaskManager* delayed_task_manager) | 498 DelayedTaskManager* delayed_task_manager) |
| 493 : name_(name.as_string()), | 499 : name_(name.as_string()), |
| 494 io_restriction_(io_restriction), | 500 io_restriction_(io_restriction), |
| 495 idle_worker_threads_stack_lock_(shared_priority_queue_.container_lock()), | 501 idle_worker_threads_stack_lock_(shared_priority_queue_.container_lock()), |
| 496 idle_worker_threads_stack_cv_for_testing_( | 502 idle_worker_threads_stack_cv_for_testing_( |
| 497 idle_worker_threads_stack_lock_.CreateConditionVariable()), | 503 idle_worker_threads_stack_lock_.CreateConditionVariable()), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 514 AutoSchedulerLock auto_lock(idle_worker_threads_stack_lock_); | 520 AutoSchedulerLock auto_lock(idle_worker_threads_stack_lock_); |
| 515 | 521 |
| 516 DCHECK(worker_threads_.empty()); | 522 DCHECK(worker_threads_.empty()); |
| 517 | 523 |
| 518 for (size_t i = 0; i < max_threads; ++i) { | 524 for (size_t i = 0; i < max_threads; ++i) { |
| 519 std::unique_ptr<SchedulerWorkerThread> worker_thread = | 525 std::unique_ptr<SchedulerWorkerThread> worker_thread = |
| 520 SchedulerWorkerThread::Create( | 526 SchedulerWorkerThread::Create( |
| 521 thread_priority, WrapUnique(new SchedulerWorkerThreadDelegateImpl( | 527 thread_priority, WrapUnique(new SchedulerWorkerThreadDelegateImpl( |
| 522 this, re_enqueue_sequence_callback, | 528 this, re_enqueue_sequence_callback, |
| 523 &shared_priority_queue_, static_cast<int>(i))), | 529 &shared_priority_queue_, static_cast<int>(i))), |
| 524 task_tracker_); | 530 task_tracker_, |
| 531 SchedulerWorkerThread::InitialWorkerState::ALIVE); |
| 525 if (!worker_thread) | 532 if (!worker_thread) |
| 526 break; | 533 break; |
| 527 idle_worker_threads_stack_.Push(worker_thread.get()); | 534 idle_worker_threads_stack_.Push(worker_thread.get()); |
| 528 worker_threads_.push_back(std::move(worker_thread)); | 535 worker_threads_.push_back(std::move(worker_thread)); |
| 529 } | 536 } |
| 530 | 537 |
| 531 #if DCHECK_IS_ON() | 538 #if DCHECK_IS_ON() |
| 532 threads_created_.Signal(); | 539 threads_created_.Signal(); |
| 533 #endif | 540 #endif |
| 534 | 541 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 556 } | 563 } |
| 557 | 564 |
| 558 void SchedulerThreadPoolImpl::RemoveFromIdleWorkerThreadsStack( | 565 void SchedulerThreadPoolImpl::RemoveFromIdleWorkerThreadsStack( |
| 559 SchedulerWorkerThread* worker_thread) { | 566 SchedulerWorkerThread* worker_thread) { |
| 560 AutoSchedulerLock auto_lock(idle_worker_threads_stack_lock_); | 567 AutoSchedulerLock auto_lock(idle_worker_threads_stack_lock_); |
| 561 idle_worker_threads_stack_.Remove(worker_thread); | 568 idle_worker_threads_stack_.Remove(worker_thread); |
| 562 } | 569 } |
| 563 | 570 |
| 564 } // namespace internal | 571 } // namespace internal |
| 565 } // namespace base | 572 } // namespace base |
| OLD | NEW |