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/task.h" | 10 #include "base/task.h" |
11 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 struct PendingTask { | 17 struct PendingTask { |
18 PendingTask( | 18 PendingTask( |
19 const tracked_objects::Location& posted_from, | 19 const tracked_objects::Location& posted_from, |
20 const base::Closure& task) | 20 const base::Closure& task) |
21 : posted_from(posted_from), | 21 : posted_from(posted_from), |
22 task(task) { | 22 task(task) { |
23 birth_tally = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); | 23 #if defined(TRACK_ALL_TASK_OBJECTS) |
| 24 post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); |
24 time_posted = tracked_objects::ThreadData::Now(); | 25 time_posted = tracked_objects::ThreadData::Now(); |
| 26 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
25 } | 27 } |
26 | 28 |
| 29 #if defined(TRACK_ALL_TASK_OBJECTS) |
27 // Counter for location where the Closure was posted from. | 30 // Counter for location where the Closure was posted from. |
28 tracked_objects::Births* birth_tally; | 31 tracked_objects::Births* post_births; |
29 | 32 |
30 // Time the task was posted. | 33 // Time the task was posted. |
31 tracked_objects::TrackedTime time_posted; | 34 TimeTicks time_posted; |
| 35 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
32 | 36 |
33 // The site this PendingTask was posted from. | 37 // The site this PendingTask was posted from. |
34 tracked_objects::Location posted_from; | 38 tracked_objects::Location posted_from; |
35 | 39 |
36 // The task to run. | 40 // The task to run. |
37 base::Closure task; | 41 base::Closure task; |
38 }; | 42 }; |
39 | 43 |
40 DWORD CALLBACK WorkItemCallback(void* param) { | 44 DWORD CALLBACK WorkItemCallback(void* param) { |
41 PendingTask* pending_task = static_cast<PendingTask*>(param); | 45 PendingTask* pending_task = static_cast<PendingTask*>(param); |
42 UNSHIPPED_TRACE_EVENT2("task", "WorkItemCallback::Run", | 46 UNSHIPPED_TRACE_EVENT2("task", "WorkItemCallback::Run", |
43 "src_file", pending_task->posted_from.file_name(), | 47 "src_file", pending_task->posted_from.file_name(), |
44 "src_func", pending_task->posted_from.function_name()); | 48 "src_func", pending_task->posted_from.function_name()); |
45 | 49 |
46 tracked_objects::TrackedTime start_time = tracked_objects::ThreadData::Now(); | 50 #if defined(TRACK_ALL_TASK_OBJECTS) |
47 | 51 TimeTicks start_of_run = tracked_objects::ThreadData::Now(); |
| 52 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
48 pending_task->task.Run(); | 53 pending_task->task.Run(); |
49 | 54 #if defined(TRACK_ALL_TASK_OBJECTS) |
50 tracked_objects::ThreadData::TallyRunOnWorkerThreadIfTracking( | 55 tracked_objects::ThreadData::TallyADeathIfActive(pending_task->post_births, |
51 pending_task->birth_tally, pending_task->time_posted, | 56 pending_task->time_posted, TimeTicks::TimeTicks(), start_of_run, |
52 start_time, tracked_objects::ThreadData::Now()); | 57 tracked_objects::ThreadData::Now()); |
| 58 #endif // defined(TRACK_ALL_TASK_OBJECTS) |
53 | 59 |
54 delete pending_task; | 60 delete pending_task; |
55 return 0; | 61 return 0; |
56 } | 62 } |
57 | 63 |
58 // Takes ownership of |pending_task| | 64 // Takes ownership of |pending_task| |
59 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) { | 65 bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) { |
60 ULONG flags = 0; | 66 ULONG flags = 0; |
61 if (task_is_slow) | 67 if (task_is_slow) |
62 flags |= WT_EXECUTELONGFUNCTION; | 68 flags |= WT_EXECUTELONGFUNCTION; |
(...skipping 18 matching lines...) Expand all Loading... |
81 return PostTaskInternal(pending_task, task_is_slow); | 87 return PostTaskInternal(pending_task, task_is_slow); |
82 } | 88 } |
83 | 89 |
84 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, | 90 bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
85 const base::Closure& task, bool task_is_slow) { | 91 const base::Closure& task, bool task_is_slow) { |
86 PendingTask* pending_task = new PendingTask(from_here, task); | 92 PendingTask* pending_task = new PendingTask(from_here, task); |
87 return PostTaskInternal(pending_task, task_is_slow); | 93 return PostTaskInternal(pending_task, task_is_slow); |
88 } | 94 } |
89 | 95 |
90 } // namespace base | 96 } // namespace base |
OLD | NEW |