Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2197)

Unified Diff: base/task_scheduler/scheduler_worker_pool_impl.h

Issue 2116163002: Add Lazy Creation and Thread Detachment Support in the Scheduler Worker Pool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR Feedback fdoray@ Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 935c79a80c5f000b549628399e0a51dc1180f1ce..59e239298bf171ff42a9ed424a50ecb188935e84 100644
--- a/base/task_scheduler/scheduler_worker_pool_impl.h
+++ b/base/task_scheduler/scheduler_worker_pool_impl.h
@@ -30,6 +30,9 @@
#include "base/threading/platform_thread.h"
namespace base {
+
+class TimeDelta;
+
namespace internal {
class DelayedTaskManager;
@@ -55,16 +58,19 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
// Creates a SchedulerWorkerPoolImpl labeled |name| with up to |max_threads|
// threads of priority |thread_priority|. |io_restriction| indicates whether
// Tasks on the constructed worker pool are allowed to make I/O calls.
- // |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.
+ // |suggested_reclaim_time| sets a suggestion on when to reclaim idle threads.
+ // The worker pool is free to ignore this value for performance or correctness
+ // reasons. |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(
StringPiece name,
ThreadPriority thread_priority,
size_t max_threads,
IORestriction io_restriction,
+ const TimeDelta& suggested_reclaim_time,
const ReEnqueueSequenceCallback& re_enqueue_sequence_callback,
TaskTracker* task_tracker,
DelayedTaskManager* delayed_task_manager);
@@ -91,6 +97,7 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
private:
class SchedulerWorkerDelegateImpl;
+ class SchedulerSingleThreadTaskRunner;
SchedulerWorkerPoolImpl(StringPiece name,
IORestriction io_restriction,
@@ -100,6 +107,7 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
bool Initialize(
ThreadPriority thread_priority,
size_t max_threads,
+ const TimeDelta& suggested_reclaim_time,
const ReEnqueueSequenceCallback& re_enqueue_sequence_callback);
// Wakes up the last worker from this worker pool to go idle, if any.
@@ -108,9 +116,15 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
// Adds |worker| to |idle_workers_stack_|.
void AddToIdleWorkersStack(SchedulerWorker* worker);
+ // Peeks from |idle_workers_stack_|.
+ const SchedulerWorker* PeekAtIdleWorkersStack() const;
+
// Removes |worker| from |idle_workers_stack_|.
void RemoveFromIdleWorkersStack(SchedulerWorker* worker);
+ // True if JoinForTesting() has been called.
+ bool HasJoinedForTesting();
+
// The name of this worker pool, used to label its worker threads.
const std::string name_;
@@ -136,7 +150,7 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
// lock as its predecessor so that a worker can be pushed to
// |idle_workers_stack_| within the scope of a Transaction (more
// details in GetWork()).
- SchedulerLock idle_workers_stack_lock_;
+ mutable SchedulerLock idle_workers_stack_lock_;
// Stack of idle workers.
SchedulerWorkerStack idle_workers_stack_;
@@ -147,6 +161,12 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
// Signaled once JoinForTesting() has returned.
WaitableEvent join_for_testing_returned_;
+ // Synchronizes access to |join_for_testing_called_|.
+ SchedulerLock join_for_testing_called_lock_;
+
+ // Indicates to the delegates that JoinForTesting() has been called.
+ bool join_for_testing_called_;
+
#if DCHECK_IS_ON()
// Signaled when all workers have been created.
WaitableEvent workers_created_;

Powered by Google App Engine
This is Rietveld 408576698