| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
| 15 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
| 16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "base/tracked_objects.h" | 17 #include "base/tracked_objects.h" |
| 18 | 18 |
| 19 using tracked_objects::TrackedTime; | 19 using tracked_objects::TrackedTime; |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 base::LazyInstance<ThreadLocalBoolean>::Leaky | 25 base::LazyInstance<ThreadLocalBoolean>::Leaky |
| 26 g_worker_pool_running_on_this_thread = LAZY_INSTANCE_INITIALIZER; | 26 g_worker_pool_running_on_this_thread = LAZY_INSTANCE_INITIALIZER; |
| 27 | 27 |
| 28 const int kIdleSecondsBeforeExit = 10 * 60; | 28 const int kIdleSecondsBeforeExit = 10 * 60; |
| 29 | 29 |
| 30 #ifdef ADDRESS_SANITIZER | |
| 31 const int kWorkerThreadStackSize = 256 * 1024; | |
| 32 #else | |
| 33 // A stack size of 64 KB is too small for the CERT_PKIXVerifyCert | |
| 34 // function of NSS because of NSS bug 439169. | |
| 35 const int kWorkerThreadStackSize = 128 * 1024; | |
| 36 #endif | |
| 37 | |
| 38 class WorkerPoolImpl { | 30 class WorkerPoolImpl { |
| 39 public: | 31 public: |
| 40 WorkerPoolImpl(); | 32 WorkerPoolImpl(); |
| 41 ~WorkerPoolImpl(); | 33 ~WorkerPoolImpl(); |
| 42 | 34 |
| 43 void PostTask(const tracked_objects::Location& from_here, | 35 void PostTask(const tracked_objects::Location& from_here, |
| 44 const base::Closure& task, bool task_is_slow); | 36 const base::Closure& task, bool task_is_slow); |
| 45 | 37 |
| 46 private: | 38 private: |
| 47 scoped_refptr<base::PosixDynamicThreadPool> pool_; | 39 scoped_refptr<base::PosixDynamicThreadPool> pool_; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 pending_task->task.Reset(); | 153 pending_task->task.Reset(); |
| 162 | 154 |
| 163 // We have enough worker threads. | 155 // We have enough worker threads. |
| 164 if (static_cast<size_t>(num_idle_threads_) >= pending_tasks_.size()) { | 156 if (static_cast<size_t>(num_idle_threads_) >= pending_tasks_.size()) { |
| 165 pending_tasks_available_cv_.Signal(); | 157 pending_tasks_available_cv_.Signal(); |
| 166 } else { | 158 } else { |
| 167 // The new PlatformThread will take ownership of the WorkerThread object, | 159 // The new PlatformThread will take ownership of the WorkerThread object, |
| 168 // which will delete itself on exit. | 160 // which will delete itself on exit. |
| 169 WorkerThread* worker = | 161 WorkerThread* worker = |
| 170 new WorkerThread(name_prefix_, this); | 162 new WorkerThread(name_prefix_, this); |
| 171 PlatformThread::CreateNonJoinable(kWorkerThreadStackSize, worker); | 163 PlatformThread::CreateNonJoinable(0, worker); |
| 172 } | 164 } |
| 173 } | 165 } |
| 174 | 166 |
| 175 PendingTask PosixDynamicThreadPool::WaitForTask() { | 167 PendingTask PosixDynamicThreadPool::WaitForTask() { |
| 176 AutoLock locked(lock_); | 168 AutoLock locked(lock_); |
| 177 | 169 |
| 178 if (terminated_) | 170 if (terminated_) |
| 179 return PendingTask(FROM_HERE, base::Closure()); | 171 return PendingTask(FROM_HERE, base::Closure()); |
| 180 | 172 |
| 181 if (pending_tasks_.empty()) { // No work available, wait for work. | 173 if (pending_tasks_.empty()) { // No work available, wait for work. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 193 return PendingTask(FROM_HERE, base::Closure()); | 185 return PendingTask(FROM_HERE, base::Closure()); |
| 194 } | 186 } |
| 195 } | 187 } |
| 196 | 188 |
| 197 PendingTask pending_task = pending_tasks_.front(); | 189 PendingTask pending_task = pending_tasks_.front(); |
| 198 pending_tasks_.pop(); | 190 pending_tasks_.pop(); |
| 199 return pending_task; | 191 return pending_task; |
| 200 } | 192 } |
| 201 | 193 |
| 202 } // namespace base | 194 } // namespace base |
| OLD | NEW |