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

Unified Diff: base/task_scheduler/task_scheduler_impl.h

Issue 2064073003: TaskScheduler: Make the worker pools of TaskSchedulerImpl configurable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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/task_scheduler_impl.h
diff --git a/base/task_scheduler/task_scheduler_impl.h b/base/task_scheduler/task_scheduler_impl.h
index 4180d9faf5ef56299c638d13259e1dce20ba7d7c..a63c0938782010eb51a3ac62369ed63033e0d801 100644
--- a/base/task_scheduler/task_scheduler_impl.h
+++ b/base/task_scheduler/task_scheduler_impl.h
@@ -5,32 +5,63 @@
#ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
#define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
+#include <stddef.h>
+
#include <memory>
+#include <string>
+#include <vector>
#include "base/base_export.h"
+#include "base/callback.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/waitable_event.h"
#include "base/task_runner.h"
#include "base/task_scheduler/delayed_task_manager.h"
+#include "base/task_scheduler/scheduler_worker_pool_impl.h"
#include "base/task_scheduler/sequence.h"
#include "base/task_scheduler/task_scheduler.h"
#include "base/task_scheduler/task_tracker.h"
#include "base/task_scheduler/task_traits.h"
+#include "base/threading/thread.h"
namespace base {
namespace internal {
class SchedulerServiceThread;
-class SchedulerWorkerPoolImpl;
// Default TaskScheduler implementation. This class is thread-safe.
class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
public:
+ struct WorkerPoolCreationArgs {
+ // Name of the pool. Used to label the pool's threads.
+ std::string name;
+
+ // Priority of the pool's threads.
+ ThreadPriority thread_priority;
+
+ // Whether I/O is allowed in the pool.
+ SchedulerWorkerPoolImpl::IORestriction io_restriction;
+
+ // Maximum number of threads in the pool.
+ size_t max_threads;
+ };
+
+ // Returns the index of the worker pool in which a task with |traits| should
+ // run.
robliao 2016/06/23 22:37:03 Also document that this should be coded in a futur
fdoray 2016/06/27 19:45:04 Done.
+ using WorkerPoolIndexForTraitsCallback =
+ Callback<size_t(const TaskTraits& traits)>;
+
// Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure to
- // do so (never returns null).
- static std::unique_ptr<TaskSchedulerImpl> Create();
+ // do so (never returns null). |worker_pools| is a list of worker pools to
robliao 2016/06/23 22:37:03 Nit: "CHECKs on failure" is sufficient.
fdoray 2016/06/27 19:45:04 Done.
+ // create. |worker_pool_index_for_traits_callback| returns the index in
robliao 2016/06/23 22:37:03 |worker_pools| describes the worker pools to creat
fdoray 2016/06/27 19:45:04 Done.
+ // |worker_pools| of the worker pool in which a task with given traits should
+ // run.
+ static std::unique_ptr<TaskSchedulerImpl> Create(
+ const std::vector<WorkerPoolCreationArgs>& worker_pools,
+ const WorkerPoolIndexForTraitsCallback&
+ worker_pool_index_for_traits_callback);
// Destroying a TaskSchedulerImpl is not allowed in production; it is always
// leaked. In tests, it can only be destroyed after JoinForTesting() has
@@ -51,9 +82,10 @@ class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
void JoinForTesting();
private:
- TaskSchedulerImpl();
+ TaskSchedulerImpl(const WorkerPoolIndexForTraitsCallback&
+ worker_pool_index_for_traits_callback);
- void Initialize();
+ void Initialize(const std::vector<WorkerPoolCreationArgs>& worker_pools);
// Returns the worker pool that runs Tasks with |traits|.
SchedulerWorkerPool* GetWorkerPoolForTraits(const TaskTraits& traits);
@@ -68,19 +100,8 @@ class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
TaskTracker task_tracker_;
DelayedTaskManager delayed_task_manager_;
-
- // Worker pool for BACKGROUND Tasks without file I/O.
- std::unique_ptr<SchedulerWorkerPoolImpl> background_worker_pool_;
-
- // Worker pool for BACKGROUND Tasks with file I/O.
- std::unique_ptr<SchedulerWorkerPoolImpl> background_file_io_worker_pool_;
-
- // Worker pool for USER_VISIBLE and USER_BLOCKING Tasks without file I/O.
- std::unique_ptr<SchedulerWorkerPoolImpl> normal_worker_pool_;
-
- // Worker pool for USER_VISIBLE and USER_BLOCKING Tasks with file I/O.
- std::unique_ptr<SchedulerWorkerPoolImpl> normal_file_io_worker_pool_;
-
+ const WorkerPoolIndexForTraitsCallback worker_pool_index_for_traits_callback_;
+ std::vector<std::unique_ptr<SchedulerWorkerPoolImpl>> worker_pools_;
std::unique_ptr<SchedulerServiceThread> service_thread_;
#if DCHECK_IS_ON()

Powered by Google App Engine
This is Rietveld 408576698