| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // The thread pool used in the POSIX implementation of WorkerPool dynamically | 5 // The thread pool used in the POSIX implementation of WorkerPool dynamically |
| 6 // adds threads as necessary to handle all tasks. It keeps old threads around | 6 // adds threads as necessary to handle all tasks. It keeps old threads around |
| 7 // for a period of time to allow them to be reused. After this waiting period, | 7 // for a period of time to allow them to be reused. After this waiting period, |
| 8 // the threads exit. This thread pool uses non-joinable threads, therefore | 8 // the threads exit. This thread pool uses non-joinable threads, therefore |
| 9 // worker threads are not joined during process shutdown. This means that | 9 // worker threads are not joined during process shutdown. This means that |
| 10 // potentially long running tasks (such as DNS lookup) do not block process | 10 // potentially long running tasks (such as DNS lookup) do not block process |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // All worker threads will share the same |name_prefix|. They will exit after | 52 // All worker threads will share the same |name_prefix|. They will exit after |
| 53 // |idle_seconds_before_exit|. | 53 // |idle_seconds_before_exit|. |
| 54 PosixDynamicThreadPool(const std::string& name_prefix, | 54 PosixDynamicThreadPool(const std::string& name_prefix, |
| 55 int idle_seconds_before_exit); | 55 int idle_seconds_before_exit); |
| 56 ~PosixDynamicThreadPool(); | 56 ~PosixDynamicThreadPool(); |
| 57 | 57 |
| 58 // Indicates that the thread pool is going away. Stops handing out tasks to | 58 // Indicates that the thread pool is going away. Stops handing out tasks to |
| 59 // worker threads. Wakes up all the idle threads to let them exit. | 59 // worker threads. Wakes up all the idle threads to let them exit. |
| 60 void Terminate(); | 60 void Terminate(); |
| 61 | 61 |
| 62 // Adds |task| to the thread pool. PosixDynamicThreadPool assumes ownership | |
| 63 // of |task|. | |
| 64 // | |
| 65 // TODO(ajwong): Remove this compatibility API once the Task -> Closure | |
| 66 // migration is finished. | |
| 67 void PostTask(const tracked_objects::Location& from_here, Task* task); | |
| 68 | |
| 69 // Adds |task| to the thread pool. | 62 // Adds |task| to the thread pool. |
| 70 void PostTask(const tracked_objects::Location& from_here, | 63 void PostTask(const tracked_objects::Location& from_here, |
| 71 const Closure& task); | 64 const Closure& task); |
| 72 | 65 |
| 73 // Worker thread method to wait for up to |idle_seconds_before_exit| for more | 66 // Worker thread method to wait for up to |idle_seconds_before_exit| for more |
| 74 // work from the thread pool. Returns NULL if no work is available. | 67 // work from the thread pool. Returns NULL if no work is available. |
| 75 PendingTask WaitForTask(); | 68 PendingTask WaitForTask(); |
| 76 | 69 |
| 77 private: | 70 private: |
| 78 friend class PosixDynamicThreadPoolPeer; | 71 friend class PosixDynamicThreadPoolPeer; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 96 // Only used for tests to ensure correct thread ordering. It will always be | 89 // Only used for tests to ensure correct thread ordering. It will always be |
| 97 // NULL in non-test code. | 90 // NULL in non-test code. |
| 98 scoped_ptr<ConditionVariable> num_idle_threads_cv_; | 91 scoped_ptr<ConditionVariable> num_idle_threads_cv_; |
| 99 | 92 |
| 100 DISALLOW_COPY_AND_ASSIGN(PosixDynamicThreadPool); | 93 DISALLOW_COPY_AND_ASSIGN(PosixDynamicThreadPool); |
| 101 }; | 94 }; |
| 102 | 95 |
| 103 } // namespace base | 96 } // namespace base |
| 104 | 97 |
| 105 #endif // BASE_THREADING_WORKER_POOL_POSIX_H_ | 98 #endif // BASE_THREADING_WORKER_POOL_POSIX_H_ |
| OLD | NEW |