| 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.h" | 5 #include "base/threading/worker_pool.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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/pending_task.h" |
| 10 #include "base/task.h" | 11 #include "base/task.h" |
| 11 #include "base/tracked_objects.h" | 12 #include "base/tracked_objects.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 struct PendingTask { | |
| 18 PendingTask( | |
| 19 const tracked_objects::Location& posted_from, | |
| 20 const base::Closure& task) | |
| 21 : posted_from(posted_from), | |
| 22 task(task) { | |
| 23 birth_tally = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); | |
| 24 time_posted = tracked_objects::ThreadData::Now(); | |
| 25 } | |
| 26 | |
| 27 // Counter for location where the Closure was posted from. | |
| 28 tracked_objects::Births* birth_tally; | |
| 29 | |
| 30 // Time the task was posted. | |
| 31 tracked_objects::TrackedTime time_posted; | |
| 32 | |
| 33 // The site this PendingTask was posted from. | |
| 34 tracked_objects::Location posted_from; | |
| 35 | |
| 36 // The task to run. | |
| 37 base::Closure task; | |
| 38 }; | |
| 39 | |
| 40 DWORD CALLBACK WorkItemCallback(void* param) { | 18 DWORD CALLBACK WorkItemCallback(void* param) { |
| 41 PendingTask* pending_task = static_cast<PendingTask*>(param); | 19 PendingTask* pending_task = static_cast<PendingTask*>(param); |
| 42 UNSHIPPED_TRACE_EVENT2("task", "WorkItemCallback::Run", | 20 UNSHIPPED_TRACE_EVENT2("task", "WorkItemCallback::Run", |
| 43 "src_file", pending_task->posted_from.file_name(), | 21 "src_file", pending_task->posted_from.file_name(), |
| 44 "src_func", pending_task->posted_from.function_name()); | 22 "src_func", pending_task->posted_from.function_name()); |
| 45 | 23 |
| 46 tracked_objects::TrackedTime start_time = | 24 tracked_objects::TrackedTime start_time = |
| 47 tracked_objects::ThreadData::NowForStartOfRun(); | 25 tracked_objects::ThreadData::NowForStartOfRun(); |
| 48 | 26 |
| 49 pending_task->task.Run(); | 27 pending_task->task.Run(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 return PostTaskInternal(pending_task, task_is_slow); | 60 return PostTaskInternal(pending_task, task_is_slow); |
| 83 } | 61 } |
| 84 | 62 |
| 85 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 63 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
| 86 const base::Closure& task, bool task_is_slow) { | 64 const base::Closure& task, bool task_is_slow) { |
| 87 PendingTask* pending_task = new PendingTask(from_here, task); | 65 PendingTask* pending_task = new PendingTask(from_here, task); |
| 88 return PostTaskInternal(pending_task, task_is_slow); | 66 return PostTaskInternal(pending_task, task_is_slow); |
| 89 } | 67 } |
| 90 | 68 |
| 91 } // namespace base | 69 } // namespace base |
| OLD | NEW |