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