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

Unified Diff: base/task_scheduler/task_scheduler.h

Issue 2873733003: Introduce SingleThreadTaskRunnerThreadMode (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | base/task_scheduler/task_scheduler_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/task_scheduler/task_scheduler.h
diff --git a/base/task_scheduler/task_scheduler.h b/base/task_scheduler/task_scheduler.h
index e36f7de53910db734ccf14bb755943418c081bfc..199a58c5a07150cc7ecb1ccfff84694429f200c4 100644
--- a/base/task_scheduler/task_scheduler.h
+++ b/base/task_scheduler/task_scheduler.h
@@ -61,6 +61,19 @@ class BASE_EXPORT TaskScheduler {
const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params;
};
+ enum class SingleThreadTaskRunnerThreadMode {
fdoray 2017/05/10 12:32:23 Declare this in a separate file, so that post_task
gab 2017/05/10 15:20:47 Agreed, feels like this belongs in task_traits.h o
robliao 2017/05/11 05:30:12 Went with a new file. This isn't really part of Ta
+ // Allow the SingleThreadTaskRunner's thread to be shared with others,
+ // allowing for efficient use of thread resources when this
+ // SingleThreadTaskRunner is idle. This is the default mode and is
+ // recommended for most code.
+ SHARED,
+ // Dedicate a single thread for this SingleThreadTaskRunner. No other tasks
+ // from any other source will be scheduled on the thread backing
+ // the SingleThreadTaskRunner. Use sparingly as this reserves an entire
+ // thread for this SingleThreadTaskRunner.
+ DEDICATED,
+ };
+
// Destroying a TaskScheduler is not allowed in production; it is always
// leaked. In tests, it should only be destroyed after JoinForTesting() has
// returned.
@@ -92,7 +105,10 @@ class BASE_EXPORT TaskScheduler {
// scheduling tasks using |traits|. Tasks run on a single thread in posting
// order.
virtual scoped_refptr<SingleThreadTaskRunner>
- CreateSingleThreadTaskRunnerWithTraits(const TaskTraits& traits) = 0;
+ CreateSingleThreadTaskRunnerWithTraits(
+ const TaskTraits& traits,
+ SingleThreadTaskRunnerThreadMode thread_mode =
+ SingleThreadTaskRunnerThreadMode::SHARED) = 0;
#if defined(OS_WIN)
// Returns a SingleThreadTaskRunner whose PostTask invocations result in
@@ -104,7 +120,10 @@ class BASE_EXPORT TaskScheduler {
// apartments as necessary. In either case, care should be taken to make sure
// COM pointers are not smuggled across apartments.
virtual scoped_refptr<SingleThreadTaskRunner>
- CreateCOMSTATaskRunnerWithTraits(const TaskTraits& traits) = 0;
+ CreateCOMSTATaskRunnerWithTraits(
+ const TaskTraits& traits,
+ SingleThreadTaskRunnerThreadMode thread_mode =
+ SingleThreadTaskRunnerThreadMode::SHARED) = 0;
#endif // defined(OS_WIN)
// Returns a vector of all histograms available in this task scheduler.
« no previous file with comments | « no previous file | base/task_scheduler/task_scheduler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698