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 // 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 // |idle_seconds_before_exit|. | 51 // |idle_seconds_before_exit|. |
52 PosixDynamicThreadPool(const std::string& name_prefix, | 52 PosixDynamicThreadPool(const std::string& name_prefix, |
53 int idle_seconds_before_exit); | 53 int idle_seconds_before_exit); |
54 | 54 |
55 // Indicates that the thread pool is going away. Stops handing out tasks to | 55 // Indicates that the thread pool is going away. Stops handing out tasks to |
56 // worker threads. Wakes up all the idle threads to let them exit. | 56 // worker threads. Wakes up all the idle threads to let them exit. |
57 void Terminate(); | 57 void Terminate(); |
58 | 58 |
59 // Adds |task| to the thread pool. | 59 // Adds |task| to the thread pool. |
60 void PostTask(const tracked_objects::Location& from_here, | 60 void PostTask(const tracked_objects::Location& from_here, |
61 const Closure& task); | 61 OnceClosure task); |
62 | 62 |
63 // Worker thread method to wait for up to |idle_seconds_before_exit| for more | 63 // Worker thread method to wait for up to |idle_seconds_before_exit| for more |
64 // work from the thread pool. Returns NULL if no work is available. | 64 // work from the thread pool. Returns NULL if no work is available. |
65 PendingTask WaitForTask(); | 65 PendingTask WaitForTask(); |
66 | 66 |
67 private: | 67 private: |
68 friend class RefCountedThreadSafe<PosixDynamicThreadPool>; | 68 friend class RefCountedThreadSafe<PosixDynamicThreadPool>; |
69 friend class PosixDynamicThreadPoolPeer; | 69 friend class PosixDynamicThreadPoolPeer; |
70 | 70 |
71 ~PosixDynamicThreadPool(); | 71 ~PosixDynamicThreadPool(); |
(...skipping 17 matching lines...) Expand all Loading... |
89 // 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 |
90 // NULL in non-test code. | 90 // NULL in non-test code. |
91 std::unique_ptr<ConditionVariable> num_idle_threads_cv_; | 91 std::unique_ptr<ConditionVariable> num_idle_threads_cv_; |
92 | 92 |
93 DISALLOW_COPY_AND_ASSIGN(PosixDynamicThreadPool); | 93 DISALLOW_COPY_AND_ASSIGN(PosixDynamicThreadPool); |
94 }; | 94 }; |
95 | 95 |
96 } // namespace base | 96 } // namespace base |
97 | 97 |
98 #endif // BASE_THREADING_WORKER_POOL_POSIX_H_ | 98 #endif // BASE_THREADING_WORKER_POOL_POSIX_H_ |
OLD | NEW |