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 TimeTicks start_of_run = tracked_objects::ThreadData::Now(); |
90 pending_task.task.Run(); | 92 pending_task.task.Run(); |
| 93 tracked_objects::ThreadData::TallyADeathIfActive(pending_task.post_births, |
| 94 pending_task.time_posted, |
| 95 start_of_run, |
| 96 NULL); |
91 } | 97 } |
92 | 98 |
93 // The WorkerThread is non-joinable, so it deletes itself. | 99 // The WorkerThread is non-joinable, so it deletes itself. |
94 delete this; | 100 delete this; |
95 } | 101 } |
96 | 102 |
97 } // namespace | 103 } // namespace |
98 | 104 |
99 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 105 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
100 Task* task, bool task_is_slow) { | 106 Task* task, bool task_is_slow) { |
101 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); | 107 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); |
102 return true; | 108 return true; |
103 } | 109 } |
104 | 110 |
105 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 111 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
106 const base::Closure& task, bool task_is_slow) { | 112 const base::Closure& task, bool task_is_slow) { |
107 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); | 113 g_lazy_worker_pool.Pointer()->PostTask(from_here, task, task_is_slow); |
108 return true; | 114 return true; |
109 } | 115 } |
110 | 116 |
111 PosixDynamicThreadPool::PendingTask::PendingTask( | 117 PosixDynamicThreadPool::PendingTask::PendingTask( |
112 const tracked_objects::Location& posted_from, | 118 const tracked_objects::Location& posted_from, |
113 const base::Closure& task) | 119 const base::Closure& task) |
114 : posted_from(posted_from), | 120 : posted_from(posted_from), |
115 task(task) { | 121 task(task) { |
| 122 #if defined(TRACK_ALL_TASK_OBJECTS) |
| 123 post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); |
| 124 time_posted = tracked_objects::ThreadData::Now(); |
| 125 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
116 } | 126 } |
117 | 127 |
118 PosixDynamicThreadPool::PendingTask::~PendingTask() { | 128 PosixDynamicThreadPool::PendingTask::~PendingTask() { |
119 } | 129 } |
120 | 130 |
121 PosixDynamicThreadPool::PosixDynamicThreadPool( | 131 PosixDynamicThreadPool::PosixDynamicThreadPool( |
122 const std::string& name_prefix, | 132 const std::string& name_prefix, |
123 int idle_seconds_before_exit) | 133 int idle_seconds_before_exit) |
124 : name_prefix_(name_prefix), | 134 : name_prefix_(name_prefix), |
125 idle_seconds_before_exit_(idle_seconds_before_exit), | 135 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()); | 217 return PendingTask(FROM_HERE, base::Closure()); |
208 } | 218 } |
209 } | 219 } |
210 | 220 |
211 PendingTask pending_task = pending_tasks_.front(); | 221 PendingTask pending_task = pending_tasks_.front(); |
212 pending_tasks_.pop(); | 222 pending_tasks_.pop(); |
213 return pending_task; | 223 return pending_task; |
214 } | 224 } |
215 | 225 |
216 } // namespace base | 226 } // namespace base |
OLD | NEW |