summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/message_loop.h4
-rw-r--r--base/task.h1
-rw-r--r--base/tracked.h6
-rw-r--r--base/worker_pool.cc13
-rw-r--r--base/worker_pool.h19
-rw-r--r--net/disk_cache/backend_impl.cc2
6 files changed, 24 insertions, 21 deletions
diff --git a/base/message_loop.h b/base/message_loop.h
index 9fdbbc0..1d1e11b 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -132,10 +132,6 @@
// loop.
//------------------------------------------------------------------------------
-// Define a macro to record where (in the sourec code) each Task is posted from.
-#define FROM_HERE tracked_objects::Location(__FUNCTION__, __FILE__, __LINE__)
-
-//------------------------------------------------------------------------------
class MessageLoop {
public:
diff --git a/base/task.h b/base/task.h
index a964a17..3a5c3cf 100644
--- a/base/task.h
+++ b/base/task.h
@@ -80,7 +80,6 @@ class MessageLoopOwnable : public tracked_objects::Tracked {
private:
friend class TimerManager; // To check is_owned_by_message_loop().
friend class MessageLoop; // To maintain posted_task_delay().
- friend class WorkerPool; // To release the task.
// Access methods used ONLY by friends in MessageLoop and TimerManager
int posted_task_delay() const { return posted_task_delay_; }
diff --git a/base/tracked.h b/base/tracked.h
index 1b5d22a..ea4092f 100644
--- a/base/tracked.h
+++ b/base/tracked.h
@@ -105,6 +105,12 @@ class Location {
//------------------------------------------------------------------------------
+// Define a macro to record the current source location.
+
+#define FROM_HERE tracked_objects::Location(__FUNCTION__, __FILE__, __LINE__)
+
+
+//------------------------------------------------------------------------------
class Births;
diff --git a/base/worker_pool.cc b/base/worker_pool.cc
index e70edad..50446c6 100644
--- a/base/worker_pool.cc
+++ b/base/worker_pool.cc
@@ -29,27 +29,30 @@
#include "base/worker_pool.h"
-#include "base/logging.h"
+#include "base/task.h"
namespace {
DWORD CALLBACK WorkItemCallback(void* param) {
Task* task = static_cast<Task*>(param);
task->Run();
- WorkerPool::RecycleTask(task);
+ delete task;
return 0;
}
} // namespace
-bool WorkerPool::Run(Task* task, bool slow) {
+bool WorkerPool::PostTask(const tracked_objects::Location& from_here,
+ Task* task, bool task_is_slow) {
+ task->SetBirthPlace(from_here);
+
ULONG flags = 0;
- if (slow)
+ if (task_is_slow)
flags |= WT_EXECUTELONGFUNCTION;
if (!QueueUserWorkItem(WorkItemCallback, task, flags)) {
DLOG(ERROR) << "QueueUserWorkItem failed: " << GetLastError();
- RecycleTask(task);
+ delete task;
return false;
}
diff --git a/base/worker_pool.h b/base/worker_pool.h
index 3b0039f..486bf9a 100644
--- a/base/worker_pool.h
+++ b/base/worker_pool.h
@@ -30,21 +30,20 @@
#ifndef BASE_WORKER_POOL_H_
#define BASE_WORKER_POOL_H_
-#include "base/task.h"
+#include "base/tracked.h"
+
+class Task;
// This is a facility that runs tasks that don't require a specific thread or
// a message loop.
class WorkerPool {
public:
- // This function posts |task| to run on a worker thread. |slow| should be used
- // for tasks that will take a long time to execute. |task| will be recycled
- // even if the function fails.
- static bool Run(Task* task, bool slow);
-
- // Recycles the task.
- static void RecycleTask(Task* task) {
- task->RecycleOrDelete();
- }
+ // This function posts |task| to run on a worker thread. |task_is_slow|
+ // should be used for tasks that will take a long time to execute. Returns
+ // false if |task| could not be posted to a worker thread. Regardless of
+ // return value, ownership of |task| is transferred to the worker pool.
+ static bool PostTask(const tracked_objects::Location& from_here,
+ Task* task, bool task_is_slow);
};
#endif // BASE_WORKER_POOL_H_
diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 59dd8e1..790b618 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -176,7 +176,7 @@ bool DelayedCacheCleanup(const std::wstring& full_path) {
return false;
}
- WorkerPool::Run(new CleanupTask(path, name), true);
+ WorkerPool::PostTask(FROM_HERE, new CleanupTask(path, name), true);
return true;
}