summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-30 04:38:38 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-30 04:38:38 +0000
commit43a973aeb04b5d0ac64bb730cadf0737de8b0cd9 (patch)
treeb1e1a322efd6c17a0446169da51ec376c6ab9a65 /base
parentb124be829f4d6907c17238ab1c84eed5acc817eb (diff)
downloadchromium_src-43a973aeb04b5d0ac64bb730cadf0737de8b0cd9.zip
chromium_src-43a973aeb04b5d0ac64bb730cadf0737de8b0cd9.tar.gz
chromium_src-43a973aeb04b5d0ac64bb730cadf0737de8b0cd9.tar.bz2
Do not use RecycleOrDelete since it is not ready for prime-time.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-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
5 files changed, 23 insertions, 20 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_