| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/debug/scoped_thread_heap_usage.h" |
| 11 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/platform_thread.h" | 17 #include "base/threading/platform_thread.h" |
| 17 #include "base/threading/thread_local.h" | 18 #include "base/threading/thread_local.h" |
| 18 #include "base/threading/worker_pool.h" | 19 #include "base/threading/worker_pool.h" |
| 19 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
| 20 #include "base/tracked_objects.h" | 21 #include "base/tracked_objects.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // Note |name.c_str()| must remain valid for for the whole life of the thread. | 83 // Note |name.c_str()| must remain valid for for the whole life of the thread. |
| 83 PlatformThread::SetName(name); | 84 PlatformThread::SetName(name); |
| 84 | 85 |
| 85 for (;;) { | 86 for (;;) { |
| 86 PendingTask pending_task = pool_->WaitForTask(); | 87 PendingTask pending_task = pool_->WaitForTask(); |
| 87 if (pending_task.task.is_null()) | 88 if (pending_task.task.is_null()) |
| 88 break; | 89 break; |
| 89 TRACE_TASK_EXECUTION("WorkerThread::ThreadMain::Run", pending_task); | 90 TRACE_TASK_EXECUTION("WorkerThread::ThreadMain::Run", pending_task); |
| 90 | 91 |
| 91 tracked_objects::TaskStopwatch stopwatch; | 92 tracked_objects::TaskStopwatch stopwatch; |
| 93 base::debug::ScopedThreadHeapUsage heap_usage; |
| 94 heap_usage.Start(); |
| 92 stopwatch.Start(); | 95 stopwatch.Start(); |
| 93 pending_task.task.Run(); | 96 pending_task.task.Run(); |
| 94 stopwatch.Stop(); | 97 stopwatch.Stop(); |
| 98 heap_usage.Stop(); |
| 95 | 99 |
| 96 tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( | 100 tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( |
| 97 pending_task.birth_tally, pending_task.time_posted, stopwatch); | 101 pending_task.birth_tally, pending_task.time_posted, stopwatch, |
| 102 heap_usage.usage()); |
| 98 } | 103 } |
| 99 | 104 |
| 100 // The WorkerThread is non-joinable, so it deletes itself. | 105 // The WorkerThread is non-joinable, so it deletes itself. |
| 101 delete this; | 106 delete this; |
| 102 } | 107 } |
| 103 | 108 |
| 104 } // namespace | 109 } // namespace |
| 105 | 110 |
| 106 // static | 111 // static |
| 107 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 112 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 return PendingTask(FROM_HERE, base::Closure()); | 189 return PendingTask(FROM_HERE, base::Closure()); |
| 185 } | 190 } |
| 186 } | 191 } |
| 187 | 192 |
| 188 PendingTask pending_task = std::move(pending_tasks_.front()); | 193 PendingTask pending_task = std::move(pending_tasks_.front()); |
| 189 pending_tasks_.pop(); | 194 pending_tasks_.pop(); |
| 190 return pending_task; | 195 return pending_task; |
| 191 } | 196 } |
| 192 | 197 |
| 193 } // namespace base | 198 } // namespace base |
| OLD | NEW |