Chromium Code Reviews| Index: base/threading/worker_pool_win.cc |
| diff --git a/base/threading/worker_pool_win.cc b/base/threading/worker_pool_win.cc |
| index 2072e525e84df34262253bce82efc4115c75fa89..28e1e5bd002add78e1aa5e1e746e5e41422857d5 100644 |
| --- a/base/threading/worker_pool_win.cc |
| +++ b/base/threading/worker_pool_win.cc |
| @@ -4,17 +4,47 @@ |
| #include "base/threading/worker_pool.h" |
| +#include "base/bind.h" |
| #include "base/logging.h" |
| #include "base/task.h" |
| +#include "base/tracked_objects.h" |
| namespace base { |
| namespace { |
| +struct PendingTask { |
| + PendingTask( |
| + const tracked_objects::Location& posted_from, |
| + const base::Closure& task) |
| + : task(task) { |
| +#if defined(TRACK_ALL_TASK_OBJECTS) |
| + post_births = tracked_objects::ThreadData::TallyABirthIfActive(posted_from); |
| + time_posted = TimeTicks::Now(); |
| +#endif // defined(TRACK_ALL_TASK_OBJECTS) |
| + } |
| + |
| +#if defined(TRACK_ALL_TASK_OBJECTS) |
| + // Counter for location where the Closure was posted from. |
| + tracked_objects::Births* post_births; |
| + |
| + // Time the task was posted. |
| + TimeTicks time_posted; |
| +#endif // defined(TRACK_ALL_TASK_OBJECTS) |
| + |
| + // The task to run. |
| + base::Closure task; |
| +}; |
| + |
| DWORD CALLBACK WorkItemCallback(void* param) { |
| - Task* task = static_cast<Task*>(param); |
| - task->Run(); |
| - delete task; |
| + PendingTask* pending_task = static_cast<PendingTask*>(param); |
| + pending_task->task.Run(); |
| +#if defined(TRACK_ALL_TASK_OBJECTS) |
| + tracked_objects::ThreadData::TallyADeathIfActive( |
| + pending_task->post_births, |
| + TimeTicks::Now() - pending_task->time_posted); |
| +#endif // defined(TRACK_ALL_TASK_OBJECTS) |
| + delete pending_task; |
| return 0; |
| } |
| @@ -22,15 +52,35 @@ DWORD CALLBACK WorkItemCallback(void* param) { |
| bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
| Task* task, bool task_is_slow) { |
| - task->SetBirthPlace(from_here); |
| + PendingTask* pending_task = |
| + new PendingTask(from_here, |
| + base::Bind(&subtle::TaskClosureAdapter::Run, |
| + new subtle::TaskClosureAdapter(task))); |
| + |
| + ULONG flags = 0; |
|
willchan no longer on Chromium
2011/07/10 16:47:33
Maybe rather than copy/pasting we should use a fun
awong
2011/07/14 23:03:30
You mean make PendingTask more global? I'm not su
willchan no longer on Chromium
2011/07/19 12:18:26
I mean taking lines 61-67 and pulling it out into
awong
2011/07/19 21:08:20
Ah. That makes more sense.
Done.
|
| + if (task_is_slow) |
| + flags |= WT_EXECUTELONGFUNCTION; |
| + |
| + if (!QueueUserWorkItem(WorkItemCallback, pending_task, flags)) { |
| + DLOG(ERROR) << "QueueUserWorkItem failed: " << GetLastError(); |
| + delete pending_task; |
| + return false; |
| + } |
| + |
| + return true; |
| +} |
| + |
| +bool WorkerPool::PostTask(const tracked_objects::Location& from_here, |
| + const base::Closure& task, bool task_is_slow) { |
| + PendingTask* pending_task = new PendingTask(from_here, task); |
| ULONG flags = 0; |
| if (task_is_slow) |
| flags |= WT_EXECUTELONGFUNCTION; |
| - if (!QueueUserWorkItem(WorkItemCallback, task, flags)) { |
| + if (!QueueUserWorkItem(WorkItemCallback, pending_task, flags)) { |
| DLOG(ERROR) << "QueueUserWorkItem failed: " << GetLastError(); |
| - delete task; |
| + delete pending_task; |
| return false; |
| } |