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