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

Side by Side Diff: base/threading/worker_pool_posix.cc

Issue 1886453003: Make PendingTask move-only and pass it by value on retaining params (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/threading/worker_pool_posix.h" 5 #include "base/threading/worker_pool_posix.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 const base::Closure& task) { 143 const base::Closure& task) {
144 PendingTask pending_task(from_here, task); 144 PendingTask pending_task(from_here, task);
145 AddTask(&pending_task); 145 AddTask(&pending_task);
146 } 146 }
147 147
148 void PosixDynamicThreadPool::AddTask(PendingTask* pending_task) { 148 void PosixDynamicThreadPool::AddTask(PendingTask* pending_task) {
149 AutoLock locked(lock_); 149 AutoLock locked(lock_);
150 DCHECK(!terminated_) 150 DCHECK(!terminated_)
151 << "This thread pool is already terminated. Do not post new tasks."; 151 << "This thread pool is already terminated. Do not post new tasks.";
152 152
153 pending_tasks_.push(*pending_task); 153 pending_tasks_.push(std::move(*pending_task));
154 pending_task->task.Reset(); 154 DCHECK(pending_task->task.is_null());
Sami 2016/04/13 11:33:00 Ditto.
tzik 2016/04/13 14:35:37 Done.
155 155
156 // We have enough worker threads. 156 // We have enough worker threads.
157 if (static_cast<size_t>(num_idle_threads_) >= pending_tasks_.size()) { 157 if (static_cast<size_t>(num_idle_threads_) >= pending_tasks_.size()) {
158 pending_tasks_available_cv_.Signal(); 158 pending_tasks_available_cv_.Signal();
159 } else { 159 } else {
160 // The new PlatformThread will take ownership of the WorkerThread object, 160 // The new PlatformThread will take ownership of the WorkerThread object,
161 // which will delete itself on exit. 161 // which will delete itself on exit.
162 WorkerThread* worker = new WorkerThread(name_prefix_, this); 162 WorkerThread* worker = new WorkerThread(name_prefix_, this);
163 PlatformThread::CreateNonJoinable(0, worker); 163 PlatformThread::CreateNonJoinable(0, worker);
164 } 164 }
(...skipping 14 matching lines...) Expand all
179 num_idle_threads_--; 179 num_idle_threads_--;
180 if (num_idle_threads_cv_.get()) 180 if (num_idle_threads_cv_.get())
181 num_idle_threads_cv_->Signal(); 181 num_idle_threads_cv_->Signal();
182 if (pending_tasks_.empty()) { 182 if (pending_tasks_.empty()) {
183 // We waited for work, but there's still no work. Return NULL to signal 183 // We waited for work, but there's still no work. Return NULL to signal
184 // the thread to terminate. 184 // the thread to terminate.
185 return PendingTask(FROM_HERE, base::Closure()); 185 return PendingTask(FROM_HERE, base::Closure());
186 } 186 }
187 } 187 }
188 188
189 PendingTask pending_task = pending_tasks_.front(); 189 PendingTask pending_task = std::move(pending_tasks_.front());
190 pending_tasks_.pop(); 190 pending_tasks_.pop();
191 return pending_task; 191 return pending_task;
192 } 192 }
193 193
194 } // namespace base 194 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698