| 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..feebd8734afe0851e906a429bccc21d4b87e81f0 100644
|
| --- a/base/threading/worker_pool_win.cc
|
| +++ b/base/threading/worker_pool_win.cc
|
| @@ -4,37 +4,80 @@
|
|
|
| #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;
|
| }
|
|
|
| -} // namespace
|
| -
|
| -bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
|
| - Task* task, bool task_is_slow) {
|
| - task->SetBirthPlace(from_here);
|
| -
|
| +// Takes ownership of |pending_task|
|
| +bool PostTaskInternal(PendingTask* pending_task, bool task_is_slow) {
|
| 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;
|
| }
|
|
|
| return true;
|
| }
|
|
|
| +} // namespace
|
| +
|
| +bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
|
| + Task* task, bool task_is_slow) {
|
| + PendingTask* pending_task =
|
| + new PendingTask(from_here,
|
| + base::Bind(&subtle::TaskClosureAdapter::Run,
|
| + new subtle::TaskClosureAdapter(task)));
|
| + return PostTaskInternal(pending_task, task_is_slow);
|
| +}
|
| +
|
| +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);
|
| + return PostTaskInternal(pending_task, task_is_slow);
|
| +}
|
| +
|
| } // namespace base
|
|
|