| OLD | NEW |
| 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 Loading... |
| 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(); | |
| 155 | 154 |
| 156 // We have enough worker threads. | 155 // We have enough worker threads. |
| 157 if (static_cast<size_t>(num_idle_threads_) >= pending_tasks_.size()) { | 156 if (static_cast<size_t>(num_idle_threads_) >= pending_tasks_.size()) { |
| 158 pending_tasks_available_cv_.Signal(); | 157 pending_tasks_available_cv_.Signal(); |
| 159 } else { | 158 } else { |
| 160 // The new PlatformThread will take ownership of the WorkerThread object, | 159 // The new PlatformThread will take ownership of the WorkerThread object, |
| 161 // which will delete itself on exit. | 160 // which will delete itself on exit. |
| 162 WorkerThread* worker = new WorkerThread(name_prefix_, this); | 161 WorkerThread* worker = new WorkerThread(name_prefix_, this); |
| 163 PlatformThread::CreateNonJoinable(0, worker); | 162 PlatformThread::CreateNonJoinable(0, worker); |
| 164 } | 163 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 179 num_idle_threads_--; | 178 num_idle_threads_--; |
| 180 if (num_idle_threads_cv_.get()) | 179 if (num_idle_threads_cv_.get()) |
| 181 num_idle_threads_cv_->Signal(); | 180 num_idle_threads_cv_->Signal(); |
| 182 if (pending_tasks_.empty()) { | 181 if (pending_tasks_.empty()) { |
| 183 // We waited for work, but there's still no work. Return NULL to signal | 182 // We waited for work, but there's still no work. Return NULL to signal |
| 184 // the thread to terminate. | 183 // the thread to terminate. |
| 185 return PendingTask(FROM_HERE, base::Closure()); | 184 return PendingTask(FROM_HERE, base::Closure()); |
| 186 } | 185 } |
| 187 } | 186 } |
| 188 | 187 |
| 189 PendingTask pending_task = pending_tasks_.front(); | 188 PendingTask pending_task = std::move(pending_tasks_.front()); |
| 190 pending_tasks_.pop(); | 189 pending_tasks_.pop(); |
| 191 return pending_task; | 190 return pending_task; |
| 192 } | 191 } |
| 193 | 192 |
| 194 } // namespace base | 193 } // namespace base |
| OLD | NEW |