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 13 matching lines...) Expand all Loading... |
24 #ifndef BASE_THREADING_WORKER_POOL_POSIX_H_ | 24 #ifndef BASE_THREADING_WORKER_POOL_POSIX_H_ |
25 #define BASE_THREADING_WORKER_POOL_POSIX_H_ | 25 #define BASE_THREADING_WORKER_POOL_POSIX_H_ |
26 #pragma once | 26 #pragma once |
27 | 27 |
28 #include <queue> | 28 #include <queue> |
29 #include <string> | 29 #include <string> |
30 | 30 |
31 #include "base/basictypes.h" | 31 #include "base/basictypes.h" |
32 #include "base/callback.h" | 32 #include "base/callback.h" |
33 #include "base/location.h" | 33 #include "base/location.h" |
| 34 #include "base/time.h" |
34 #include "base/memory/ref_counted.h" | 35 #include "base/memory/ref_counted.h" |
35 #include "base/memory/scoped_ptr.h" | 36 #include "base/memory/scoped_ptr.h" |
36 #include "base/synchronization/condition_variable.h" | 37 #include "base/synchronization/condition_variable.h" |
37 #include "base/synchronization/lock.h" | 38 #include "base/synchronization/lock.h" |
38 #include "base/threading/platform_thread.h" | 39 #include "base/threading/platform_thread.h" |
| 40 #include "base/tracked_objects.h" |
39 | 41 |
40 class Task; | 42 class Task; |
41 | 43 |
42 namespace base { | 44 namespace base { |
43 | 45 |
44 class BASE_EXPORT PosixDynamicThreadPool | 46 class BASE_EXPORT PosixDynamicThreadPool |
45 : public RefCountedThreadSafe<PosixDynamicThreadPool> { | 47 : public RefCountedThreadSafe<PosixDynamicThreadPool> { |
46 public: | 48 public: |
47 class PosixDynamicThreadPoolPeer; | 49 class PosixDynamicThreadPoolPeer; |
48 | 50 |
49 struct PendingTask { | 51 struct PendingTask { |
50 PendingTask(const tracked_objects::Location& posted_from, | 52 PendingTask(const tracked_objects::Location& posted_from, |
51 const base::Closure& task); | 53 const base::Closure& task); |
52 ~PendingTask(); | 54 ~PendingTask(); |
53 // TODO(ajwong): After we figure out why Mac's ~AtExitManager dies when | 55 |
54 // destructing the lock, add in extra info so we can call | 56 #if defined(TRACK_ALL_TASK_OBJECTS) |
55 // tracked_objects::TallyADeathIfActive() and | 57 // Counter for location where the Closure was posted from. |
56 // tracked_objects::TallyABirthIfActive correctly. | 58 tracked_objects::Births* post_births; |
| 59 |
| 60 // Time the task was posted. |
| 61 TimeTicks time_posted; |
| 62 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
57 | 63 |
58 const tracked_objects::Location posted_from; | 64 const tracked_objects::Location posted_from; |
59 | 65 |
60 // The task to run. | 66 // The task to run. |
61 base::Closure task; | 67 base::Closure task; |
62 }; | 68 }; |
63 | 69 |
64 // All worker threads will share the same |name_prefix|. They will exit after | 70 // All worker threads will share the same |name_prefix|. They will exit after |
65 // |idle_seconds_before_exit|. | 71 // |idle_seconds_before_exit|. |
66 PosixDynamicThreadPool(const std::string& name_prefix, | 72 PosixDynamicThreadPool(const std::string& name_prefix, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // Only used for tests to ensure correct thread ordering. It will always be | 114 // Only used for tests to ensure correct thread ordering. It will always be |
109 // NULL in non-test code. | 115 // NULL in non-test code. |
110 scoped_ptr<ConditionVariable> num_idle_threads_cv_; | 116 scoped_ptr<ConditionVariable> num_idle_threads_cv_; |
111 | 117 |
112 DISALLOW_COPY_AND_ASSIGN(PosixDynamicThreadPool); | 118 DISALLOW_COPY_AND_ASSIGN(PosixDynamicThreadPool); |
113 }; | 119 }; |
114 | 120 |
115 } // namespace base | 121 } // namespace base |
116 | 122 |
117 #endif // BASE_THREADING_WORKER_POOL_POSIX_H_ | 123 #endif // BASE_THREADING_WORKER_POOL_POSIX_H_ |
OLD | NEW |