Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: base/task_scheduler/scheduler_worker_pool_impl.cc

Issue 2692863012: SchedulerWorker Refcounting for Destruction in Production (Closed)
Patch Set: Remove Last Vestiges of std::unique_ptr SchedulerWorker Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // Sequence for all Tasks posted through this TaskRunner. 123 // Sequence for all Tasks posted through this TaskRunner.
124 const scoped_refptr<Sequence> sequence_ = new Sequence; 124 const scoped_refptr<Sequence> sequence_ = new Sequence;
125 125
126 const TaskTraits traits_; 126 const TaskTraits traits_;
127 SchedulerWorkerPool* const worker_pool_; 127 SchedulerWorkerPool* const worker_pool_;
128 128
129 DISALLOW_COPY_AND_ASSIGN(SchedulerSequencedTaskRunner); 129 DISALLOW_COPY_AND_ASSIGN(SchedulerSequencedTaskRunner);
130 }; 130 };
131 131
132 // Only used in DCHECKs. 132 // Only used in DCHECKs.
133 bool ContainsWorker( 133 bool ContainsWorker(const std::vector<scoped_refptr<SchedulerWorker>>& workers,
134 const std::vector<std::unique_ptr<SchedulerWorker>>& workers, 134 const SchedulerWorker* worker) {
135 const SchedulerWorker* worker) {
136 auto it = std::find_if(workers.begin(), workers.end(), 135 auto it = std::find_if(workers.begin(), workers.end(),
137 [worker](const std::unique_ptr<SchedulerWorker>& i) { 136 [worker](const scoped_refptr<SchedulerWorker>& i) {
138 return i.get() == worker; 137 return i.get() == worker;
139 }); 138 });
140 return it != workers.end(); 139 return it != workers.end();
141 } 140 }
142 141
143 } // namespace 142 } // namespace
144 143
145 // A task runner that runs tasks with the SINGLE_THREADED ExecutionMode. 144 // A task runner that runs tasks with the SINGLE_THREADED ExecutionMode.
146 class SchedulerWorkerPoolImpl::SchedulerSingleThreadTaskRunner : 145 class SchedulerWorkerPoolImpl::SchedulerSingleThreadTaskRunner :
147 public SingleThreadTaskRunner { 146 public SingleThreadTaskRunner {
148 public: 147 public:
149 // Constructs a SchedulerSingleThreadTaskRunner which can be used to post 148 // Constructs a SchedulerSingleThreadTaskRunner which can be used to post
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 // This ensures that they are woken up in order of index and that the ALIVE 689 // This ensures that they are woken up in order of index and that the ALIVE
691 // worker is on top of the stack. 690 // worker is on top of the stack.
692 for (int index = params.max_threads() - 1; index >= 0; --index) { 691 for (int index = params.max_threads() - 1; index >= 0; --index) {
693 const bool is_standby_lazy = 692 const bool is_standby_lazy =
694 params.standby_thread_policy() == 693 params.standby_thread_policy() ==
695 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY; 694 SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY;
696 const SchedulerWorker::InitialState initial_state = 695 const SchedulerWorker::InitialState initial_state =
697 (index == 0 && !is_standby_lazy) 696 (index == 0 && !is_standby_lazy)
698 ? SchedulerWorker::InitialState::ALIVE 697 ? SchedulerWorker::InitialState::ALIVE
699 : SchedulerWorker::InitialState::DETACHED; 698 : SchedulerWorker::InitialState::DETACHED;
700 std::unique_ptr<SchedulerWorker> worker = SchedulerWorker::Create( 699 scoped_refptr<SchedulerWorker> worker = SchedulerWorker::Create(
701 params.priority_hint(), 700 params.priority_hint(),
702 MakeUnique<SchedulerWorkerDelegateImpl>( 701 MakeUnique<SchedulerWorkerDelegateImpl>(
703 this, re_enqueue_sequence_callback, &shared_priority_queue_, index), 702 this, re_enqueue_sequence_callback, &shared_priority_queue_, index),
704 task_tracker_, initial_state, params.backward_compatibility()); 703 task_tracker_, initial_state, params.backward_compatibility());
705 if (!worker) 704 if (!worker)
706 break; 705 break;
707 idle_workers_stack_.Push(worker.get()); 706 idle_workers_stack_.Push(worker.get());
708 workers_[index] = std::move(worker); 707 workers_[index] = std::move(worker);
709 } 708 }
710 709
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 AutoSchedulerLock auto_lock(idle_workers_stack_lock_); 758 AutoSchedulerLock auto_lock(idle_workers_stack_lock_);
760 idle_workers_stack_.Remove(worker); 759 idle_workers_stack_.Remove(worker);
761 } 760 }
762 761
763 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() { 762 bool SchedulerWorkerPoolImpl::CanWorkerDetachForTesting() {
764 return !worker_detachment_disallowed_.IsSet(); 763 return !worker_detachment_disallowed_.IsSet();
765 } 764 }
766 765
767 } // namespace internal 766 } // namespace internal
768 } // namespace base 767 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool_impl.h ('k') | base/task_scheduler/scheduler_worker_stack_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698