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 <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 139 } |
140 | 140 |
141 void PosixDynamicThreadPool::PostTask( | 141 void PosixDynamicThreadPool::PostTask( |
142 const tracked_objects::Location& from_here, | 142 const tracked_objects::Location& from_here, |
143 base::Closure task) { | 143 base::Closure task) { |
144 PendingTask pending_task(from_here, std::move(task)); | 144 PendingTask pending_task(from_here, std::move(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 DCHECK(pending_task); |
| 150 DCHECK(pending_task->task); |
149 AutoLock locked(lock_); | 151 AutoLock locked(lock_); |
150 | 152 |
151 pending_tasks_.push(std::move(*pending_task)); | 153 pending_tasks_.push(std::move(*pending_task)); |
152 | 154 |
153 // We have enough worker threads. | 155 // We have enough worker threads. |
154 if (static_cast<size_t>(num_idle_threads_) >= pending_tasks_.size()) { | 156 if (static_cast<size_t>(num_idle_threads_) >= pending_tasks_.size()) { |
155 pending_tasks_available_cv_.Signal(); | 157 pending_tasks_available_cv_.Signal(); |
156 } else { | 158 } else { |
157 // The new PlatformThread will take ownership of the WorkerThread object, | 159 // The new PlatformThread will take ownership of the WorkerThread object, |
158 // which will delete itself on exit. | 160 // which will delete itself on exit. |
(...skipping 20 matching lines...) Expand all Loading... |
179 return PendingTask(FROM_HERE, base::Closure()); | 181 return PendingTask(FROM_HERE, base::Closure()); |
180 } | 182 } |
181 } | 183 } |
182 | 184 |
183 PendingTask pending_task = std::move(pending_tasks_.front()); | 185 PendingTask pending_task = std::move(pending_tasks_.front()); |
184 pending_tasks_.pop(); | 186 pending_tasks_.pop(); |
185 return pending_task; | 187 return pending_task; |
186 } | 188 } |
187 | 189 |
188 } // namespace base | 190 } // namespace base |
OLD | NEW |