Index: base/task_scheduler/scheduler_worker_pool_impl.h |
diff --git a/base/task_scheduler/scheduler_worker_pool_impl.h b/base/task_scheduler/scheduler_worker_pool_impl.h |
index 0c1fdcd13a2e71506164efb7abc4dff420f295ea..f304b8a641469dccc77821d030f3b9106c35ff97 100644 |
--- a/base/task_scheduler/scheduler_worker_pool_impl.h |
+++ b/base/task_scheduler/scheduler_worker_pool_impl.h |
@@ -45,23 +45,33 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool { |
// from it. |
using ReEnqueueSequenceCallback = Callback<void(scoped_refptr<Sequence>)>; |
+ // Constructs a pool without workers. Tasks can be posted to the pool, but |
+ // they won't run until workers are created. To create workers and start |
+ // running tasks, call Start(). |
+ // |
+ // |name| is used to label the pool's threads ("TaskScheduler" + |name| + |
+ // index) and histograms ("TaskScheduler." + histogram name + "." + |name| + |
+ // extra suffixes). |priority_hint| is the preferred thread priority; the |
+ // actual thread priority depends on shutdown state and platform capabilities. |
+ // |re_enqueue_sequence_callback| will be invoked after a worker of this |
robliao
2017/04/05 23:29:23
Use the above ReEnqueueSequenceCallback comment he
fdoray
2017/04/06 15:07:12
Done.
|
+ // worker pool tries to run a Task. |task_tracker| keeps track of tasks. |
+ // |delayed_task_manager| handles tasks posted with a delay. |
+ SchedulerWorkerPoolImpl( |
+ const std::string& name, |
+ ThreadPriority priority_hint, |
+ ReEnqueueSequenceCallback re_enqueue_sequence_callback, |
+ TaskTracker* task_tracker, |
+ DelayedTaskManager* delayed_task_manager); |
+ |
+ // Creates workers following the |params| specification, allowing existing and |
+ // future tasks to run. Can only be called once. CHECKs on failure. |
+ void Start(const SchedulerWorkerPoolParams& params); |
+ |
// Destroying a SchedulerWorkerPoolImpl returned by Create() is not allowed in |
// production; it is always leaked. In tests, it can only be destroyed after |
// JoinForTesting() has returned. |
~SchedulerWorkerPoolImpl() override; |
- // Creates a SchedulerWorkerPoolImpl following the |worker_pool_params| |
- // specification. |re_enqueue_sequence_callback| will be invoked after a |
- // worker of this worker pool tries to run a Task. |task_tracker| is used to |
- // handle shutdown behavior of Tasks. |delayed_task_manager| handles Tasks |
- // posted with a delay. Returns nullptr on failure to create a worker pool |
- // with at least one thread. |
- static std::unique_ptr<SchedulerWorkerPoolImpl> Create( |
- const SchedulerWorkerPoolParams& params, |
- const ReEnqueueSequenceCallback& re_enqueue_sequence_callback, |
- TaskTracker* task_tracker, |
- DelayedTaskManager* delayed_task_manager); |
- |
// SchedulerWorkerPool: |
scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
const TaskTraits& traits) override; |
@@ -113,10 +123,6 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool { |
TaskTracker* task_tracker, |
DelayedTaskManager* delayed_task_manager); |
- bool Initialize( |
- const SchedulerWorkerPoolParams& params, |
- const ReEnqueueSequenceCallback& re_enqueue_sequence_callback); |
- |
// Wakes up the last worker from this worker pool to go idle, if any. |
void WakeUpOneWorker(); |
@@ -132,18 +138,20 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool { |
// Returns true if worker thread detachment is permitted. |
bool CanWorkerDetachForTesting(); |
- // The name of this worker pool, used to label its worker threads. |
const std::string name_; |
- |
- // All worker owned by this worker pool. Only modified during initialization |
- // of the worker pool. |
- std::vector<scoped_refptr<SchedulerWorker>> workers_; |
+ const ThreadPriority priority_hint_; |
+ const ReEnqueueSequenceCallback re_enqueue_sequence_callback_; |
// PriorityQueue from which all threads of this worker pool get work. |
PriorityQueue shared_priority_queue_; |
- // Suggested reclaim time for workers. |
- const TimeDelta suggested_reclaim_time_; |
+ // All worker owned by this worker pool. Never modified after Start() (i.e. |
robliao
2017/04/05 23:29:23
s/worker/workers/
fdoray
2017/04/06 15:07:12
Done.
|
+ // can be read without synchronization once |workers_created_.IsSignaled()|). |
+ std::vector<scoped_refptr<SchedulerWorker>> workers_; |
+ |
+ // Suggested reclaim time for workers. Never modified after Start() (i.e. can |
+ // be read without synchronization once |workers_created_.IsSignaled()|). |
+ TimeDelta suggested_reclaim_time_; |
// Synchronizes access to |idle_workers_stack_| and |
// |idle_workers_stack_cv_for_testing_|. Has |shared_priority_queue_|'s |
@@ -171,7 +179,7 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool { |
#if DCHECK_IS_ON() |
// Signaled when all workers have been created. |
- WaitableEvent workers_created_; |
+ mutable WaitableEvent workers_created_; |
#endif |
// TaskScheduler.DetachDuration.[worker pool name] histogram. Intentionally |