diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-26 18:25:16 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-26 18:25:16 +0000 |
commit | 180c85e3e3691042ab617fd0755dcde6e75d5fbd (patch) | |
tree | b9d4fd7a77f7f54dce4463960326ef7b0cd7a270 /base/threading/worker_pool_win.cc | |
parent | 324ab8e0d77303333f8ad7de3b54d248587687db (diff) | |
download | chromium_src-180c85e3e3691042ab617fd0755dcde6e75d5fbd.zip chromium_src-180c85e3e3691042ab617fd0755dcde6e75d5fbd.tar.gz chromium_src-180c85e3e3691042ab617fd0755dcde6e75d5fbd.tar.bz2 |
Support Closure in ALL the loops!
Add an overload for PostTask into MessageLoopProxy, and WorkerPool.
BUG=35223
TEST=unittests.
Review URL: http://codereview.chromium.org/7316015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94129 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/threading/worker_pool_win.cc')
-rw-r--r-- | base/threading/worker_pool_win.cc | 67 |
1 files changed, 55 insertions, 12 deletions
diff --git a/base/threading/worker_pool_win.cc b/base/threading/worker_pool_win.cc index 2072e52..2aa423f 100644 --- a/base/threading/worker_pool_win.cc +++ b/base/threading/worker_pool_win.cc @@ -1,40 +1,83 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #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 |