Index: base/threading/worker_pool_posix.h |
diff --git a/base/threading/worker_pool_posix.h b/base/threading/worker_pool_posix.h |
index 9bb9edaba186179a24932370aa64d9321f64c1d7..24f0d886114be7797fe63b80b5cbe9e961a08857 100644 |
--- a/base/threading/worker_pool_posix.h |
+++ b/base/threading/worker_pool_posix.h |
@@ -29,11 +29,13 @@ |
#include <string> |
#include "base/basictypes.h" |
+#include "base/callback.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/synchronization/condition_variable.h" |
#include "base/synchronization/lock.h" |
#include "base/threading/platform_thread.h" |
+#include "base/tracked.h" |
class Task; |
@@ -44,6 +46,21 @@ class BASE_API PosixDynamicThreadPool |
public: |
class PosixDynamicThreadPoolPeer; |
+ struct PendingTask { |
+ PendingTask(const tracked_objects::Location& posted_from, |
+ const base::Closure& task); |
+#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; |
+ }; |
+ |
// All worker threads will share the same |name_prefix|. They will exit after |
// |idle_seconds_before_exit|. |
PosixDynamicThreadPool(const std::string& name_prefix, |
@@ -56,15 +73,25 @@ class BASE_API PosixDynamicThreadPool |
// Adds |task| to the thread pool. PosixDynamicThreadPool assumes ownership |
// of |task|. |
- void PostTask(Task* task); |
- |
+ // |
+ // TODO(ajwong): Remove this compatibility API once the Task -> Closure |
+ // migration is finished. |
+ void PostTask(const tracked_objects::Location& from_here, Task* task); |
+ |
+ // Adds |task| to the thread pool. |
+ void PostTask(const tracked_objects::Location& from_here, |
+ const base::Closure& task); |
// Worker thread method to wait for up to |idle_seconds_before_exit| for more |
// work from the thread pool. Returns NULL if no work is available. |
- Task* WaitForTask(); |
+ PendingTask WaitForTask(); |
private: |
friend class PosixDynamicThreadPoolPeer; |
+ // Adds pending_task to the thread pool. This function will clear |
+ // |pending_task->task|. |
+ void AddTask(PendingTask* pending_task); |
+ |
const std::string name_prefix_; |
const int idle_seconds_before_exit_; |
@@ -73,9 +100,9 @@ class BASE_API PosixDynamicThreadPool |
// Signal()s worker threads to let them know more tasks are available. |
// Also used for Broadcast()'ing to worker threads to let them know the pool |
// is being deleted and they can exit. |
- ConditionVariable tasks_available_cv_; |
+ ConditionVariable pending_tasks_available_cv_; |
int num_idle_threads_; |
- std::queue<Task*> tasks_; |
+ std::queue<PendingTask> pending_tasks_; |
bool terminated_; |
// Only used for tests to ensure correct thread ordering. It will always be |
// NULL in non-test code. |