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 #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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 "%s/%d", name_prefix_.c_str(), PlatformThread::CurrentId()); | 80 "%s/%d", name_prefix_.c_str(), PlatformThread::CurrentId()); |
81 PlatformThread::SetName(name.c_str()); | 81 PlatformThread::SetName(name.c_str()); |
82 | 82 |
83 for (;;) { | 83 for (;;) { |
84 PosixDynamicThreadPool::PendingTask pending_task = pool_->WaitForTask(); | 84 PosixDynamicThreadPool::PendingTask pending_task = pool_->WaitForTask(); |
85 if (pending_task.task.is_null()) | 85 if (pending_task.task.is_null()) |
86 break; | 86 break; |
87 UNSHIPPED_TRACE_EVENT2("task", "WorkerThread::ThreadMain::Run", | 87 UNSHIPPED_TRACE_EVENT2("task", "WorkerThread::ThreadMain::Run", |
88 "src_file", pending_task.posted_from.file_name(), | 88 "src_file", pending_task.posted_from.file_name(), |
89 "src_func", pending_task.posted_from.function_name()); | 89 "src_func", pending_task.posted_from.function_name()); |
| 90 |
| 91 #if defined(TRACK_ALL_TASK_OBJECTS) |
| 92 TimeTicks start_of_run = tracked_objects::ThreadData::Now(); |
| 93 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
90 pending_task.task.Run(); | 94 pending_task.task.Run(); |
| 95 #if defined(TRACK_ALL_TASK_OBJECTS) |
| 96 tracked_objects::ThreadData::TallyADeathIfActive(pending_task.post_births, |
| 97 pending_task.time_posted, TimeTicks::TimeTicks(), start_of_run); |
| 98 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
91 } | 99 } |
92 | 100 |
93 // The WorkerThread is non-joinable, so it deletes itself. | 101 // The WorkerThread is non-joinable, so it deletes itself. |
94 delete this; | 102 delete this; |
95 } | 103 } |
96 | 104 |
97 } // namespace | 105 } // namespace |
98 | 106 |
99 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 107 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
100 Task* task, bool task_is_slow) { | 108 Task* task, bool task_is_slow) { |
101 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); | 109 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); |
102 return true; | 110 return true; |
103 } | 111 } |
104 | 112 |
105 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 113 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
106 const base::Closure& task, bool task_is_slow) { | 114 const base::Closure& task, bool task_is_slow) { |
107 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); | 115 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); |
108 return true; | 116 return true; |
109 } | 117 } |
110 | 118 |
111 PosixDynamicThreadPool::PendingTask::PendingTask( | 119 PosixDynamicThreadPool::PendingTask::PendingTask( |
112 const tracked_objects::Location& posted_from, | 120 const tracked_objects::Location& posted_from, |
113 const base::Closure& task) | 121 const base::Closure& task) |
114 : posted_from(posted_from), | 122 : posted_from(posted_from), |
115 task(task) { | 123 task(task) { |
| 124 #if defined(TRACK_ALL_TASK_OBJECTS) |
| 125 post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); |
| 126 time_posted = tracked_objects::ThreadData::Now(); |
| 127 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
116 } | 128 } |
117 | 129 |
118 PosixDynamicThreadPool::PendingTask::~PendingTask() { | 130 PosixDynamicThreadPool::PendingTask::~PendingTask() { |
119 } | 131 } |
120 | 132 |
121 PosixDynamicThreadPool::PosixDynamicThreadPool( | 133 PosixDynamicThreadPool::PosixDynamicThreadPool( |
122 const std::string& name_prefix, | 134 const std::string& name_prefix, |
123 int idle_seconds_before_exit) | 135 int idle_seconds_before_exit) |
124 : name_prefix_(name_prefix), | 136 : name_prefix_(name_prefix), |
125 idle_seconds_before_exit_(idle_seconds_before_exit), | 137 idle_seconds_before_exit_(idle_seconds_before_exit), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 return PendingTask(FROM_HERE, base::Closure()); | 219 return PendingTask(FROM_HERE, base::Closure()); |
208 } | 220 } |
209 } | 221 } |
210 | 222 |
211 PendingTask pending_task = pending_tasks_.front(); | 223 PendingTask pending_task = pending_tasks_.front(); |
212 pending_tasks_.pop(); | 224 pending_tasks_.pop(); |
213 return pending_task; | 225 return pending_task; |
214 } | 226 } |
215 | 227 |
216 } // namespace base | 228 } // namespace base |
OLD | NEW |