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

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 Continuation 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 85b852f1ab9951bbc6df739b056b9922d5136a87..bf9eaff0835c7c0de3a04d42b6ea4bf910c018af 100644
--- a/base/task_scheduler/scheduler_worker_pool_impl.h
+++ b/base/task_scheduler/scheduler_worker_pool_impl.h
@@ -31,6 +31,9 @@
#include "base/threading/platform_thread.h"
namespace base {
+
+class TimeDelta;
+
namespace internal {
class DelayedTaskManager;
@@ -67,6 +70,14 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
// allowed to complete their execution. This can only be called once.
void JoinForTesting();
+ // Disallows worker thread detachment. If the suggested reclaim time is not
fdoray 2016/07/20 14:15:43 // [...], then the test should call this before Jo
robliao 2016/07/20 19:44:01 Unless the test requires the ability to detach. I'
+ // TimeDelta::Max(), then the test should call this before the detach code can
+ // run. The safest place to do this is before the first set of work is
+ // dispatched (the worker pool is idle and steady state) or before the last
+ // synchronization point for all workers (all threads are busy and can't be
+ // reclaimed).
+ void DisallowWorkerDetachmentForTesting();
+
// SchedulerWorkerPool:
scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(
const TaskTraits& traits,
@@ -81,11 +92,13 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
SchedulerWorker* worker) override;
private:
+ class SchedulerSingleThreadTaskRunner;
class SchedulerWorkerDelegateImpl;
SchedulerWorkerPoolImpl(StringPiece name,
SchedulerWorkerPoolParams::IORestriction
io_restriction,
+ const TimeDelta& suggested_reclaim_time,
TaskTracker* task_tracker,
DelayedTaskManager* delayed_task_manager);
@@ -100,9 +113,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);
+ // 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_;
@@ -123,12 +142,15 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
// Indicates whether Tasks on this worker pool are allowed to make I/O calls.
const SchedulerWorkerPoolParams::IORestriction io_restriction_;
+ // Suggested reclaim time for workers.
+ const TimeDelta suggested_reclaim_time_;
+
// Synchronizes access to |idle_workers_stack_| and
// |idle_workers_stack_cv_for_testing_|. Has |shared_priority_queue_|'s
// 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_;
@@ -139,6 +161,13 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
// Signaled once JoinForTesting() has returned.
WaitableEvent join_for_testing_returned_;
+ // Synchronizes access to |worker_detachment_allowed_|.
+ SchedulerLock worker_detachment_allowed_lock_;
+
+ // Indicates to the delegates that workers are permitted to detach their
+ // threads.
+ bool worker_detachment_allowed_;
+
#if DCHECK_IS_ON()
// Signaled when all workers have been created.
WaitableEvent workers_created_;

Powered by Google App Engine
This is Rietveld 408576698