| 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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 428     // - |sequence| is already in a PriorityQueue (not necessarily | 428     // - |sequence| is already in a PriorityQueue (not necessarily | 
| 429     //   |shared_priority_queue_|), or, | 429     //   |shared_priority_queue_|), or, | 
| 430     // - A worker is running a Task from |sequence|. It will insert |sequence| | 430     // - A worker is running a Task from |sequence|. It will insert |sequence| | 
| 431     //   in a PriorityQueue once it's done running the Task. | 431     //   in a PriorityQueue once it's done running the Task. | 
| 432     const auto sequence_sort_key = sequence->GetSortKey(); | 432     const auto sequence_sort_key = sequence->GetSortKey(); | 
| 433     priority_queue->BeginTransaction()->Push(std::move(sequence), | 433     priority_queue->BeginTransaction()->Push(std::move(sequence), | 
| 434                                              sequence_sort_key); | 434                                              sequence_sort_key); | 
| 435 | 435 | 
| 436     // Wake up a worker to process |sequence|. | 436     // Wake up a worker to process |sequence|. | 
| 437     if (worker) | 437     if (worker) | 
| 438       worker->WakeUp(); | 438       WakeUpWorker(worker); | 
| 439     else | 439     else | 
| 440       WakeUpOneWorker(); | 440       WakeUpOneWorker(); | 
| 441   } | 441   } | 
| 442 } | 442 } | 
| 443 | 443 | 
| 444 SchedulerWorkerPoolImpl::SchedulerSingleThreadTaskRunner:: | 444 SchedulerWorkerPoolImpl::SchedulerSingleThreadTaskRunner:: | 
| 445     SchedulerSingleThreadTaskRunner(const TaskTraits& traits, | 445     SchedulerSingleThreadTaskRunner(const TaskTraits& traits, | 
| 446                                     SchedulerWorkerPool* worker_pool, | 446                                     SchedulerWorkerPool* worker_pool, | 
| 447                                     SchedulerWorker* worker) | 447                                     SchedulerWorker* worker) | 
| 448     : traits_(traits), | 448     : traits_(traits), | 
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 713     workers_.push_back(std::move(worker)); | 713     workers_.push_back(std::move(worker)); | 
| 714   } | 714   } | 
| 715 | 715 | 
| 716 #if DCHECK_IS_ON() | 716 #if DCHECK_IS_ON() | 
| 717   workers_created_.Signal(); | 717   workers_created_.Signal(); | 
| 718 #endif | 718 #endif | 
| 719 | 719 | 
| 720   return !workers_.empty(); | 720   return !workers_.empty(); | 
| 721 } | 721 } | 
| 722 | 722 | 
|  | 723 void SchedulerWorkerPoolImpl::WakeUpWorker(SchedulerWorker* worker) { | 
|  | 724   DCHECK(worker); | 
|  | 725   RemoveFromIdleWorkersStack(worker); | 
|  | 726   worker->WakeUp(); | 
|  | 727 } | 
|  | 728 | 
| 723 void SchedulerWorkerPoolImpl::WakeUpOneWorker() { | 729 void SchedulerWorkerPoolImpl::WakeUpOneWorker() { | 
| 724   SchedulerWorker* worker; | 730   SchedulerWorker* worker; | 
| 725   { | 731   { | 
| 726     AutoSchedulerLock auto_lock(idle_workers_stack_lock_); | 732     AutoSchedulerLock auto_lock(idle_workers_stack_lock_); | 
| 727     worker = idle_workers_stack_.Pop(); | 733     worker = idle_workers_stack_.Pop(); | 
| 728   } | 734   } | 
| 729   if (worker) | 735   if (worker) | 
| 730     worker->WakeUp(); | 736     worker->WakeUp(); | 
| 731 } | 737 } | 
| 732 | 738 | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 756   AutoSchedulerLock auto_lock(idle_workers_stack_lock_); | 762   AutoSchedulerLock auto_lock(idle_workers_stack_lock_); | 
| 757   idle_workers_stack_.Remove(worker); | 763   idle_workers_stack_.Remove(worker); | 
| 758 } | 764 } | 
| 759 | 765 | 
| 760 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { | 766 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { | 
| 761   return !worker_detachment_disallowed_.IsSet(); | 767   return !worker_detachment_disallowed_.IsSet(); | 
| 762 } | 768 } | 
| 763 | 769 | 
| 764 }  // namespace internal | 770 }  // namespace internal | 
| 765 }  // namespace base | 771 }  // namespace base | 
| OLD | NEW | 
|---|