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(); |
50 | 28 |
51 tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( | 29 tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( |
52 pending_task->birth_tally, pending_task->time_posted, | 30 pending_task->birth_tally, |
53 start_time, tracked_objects::ThreadData::NowForEndOfRun()); | 31 tracked_objects::TrackedTime(pending_task->time_posted), start_time, |
| 32 tracked_objects::ThreadData::NowForEndOfRun()); |
54 | 33 |
55 delete pending_task; | 34 delete pending_task; |
56 return 0; | 35 return 0; |
57 } | 36 } |
58 | 37 |
59 // Takes ownership of |pending_task| | 38 // Takes ownership of |pending_task| |
60 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) { | 39 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) { |
61 ULONG flags = 0; | 40 ULONG flags = 0; |
62 if (task_is_slow) | 41 if (task_is_slow) |
63 flags |= WT_EXECUTELONGFUNCTION; | 42 flags |= WT_EXECUTELONGFUNCTION; |
(...skipping 18 matching lines...) Expand all Loading... |
82 return PostTaskInternal(pending_task, task_is_slow); | 61 return PostTaskInternal(pending_task, task_is_slow); |
83 } | 62 } |
84 | 63 |
85 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 64 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
86 const base::Closure& task, bool task_is_slow) { | 65 const base::Closure& task, bool task_is_slow) { |
87 PendingTask* pending_task = new PendingTask(from_here, task); | 66 PendingTask* pending_task = new PendingTask(from_here, task); |
88 return PostTaskInternal(pending_task, task_is_slow); | 67 return PostTaskInternal(pending_task, task_is_slow); |
89 } | 68 } |
90 | 69 |
91 } // namespace base | 70 } // namespace base |
OLD | NEW |