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

Unified Diff: base/task_scheduler/post_task.h

Issue 2464963002: TaskScheduler: Remove base::ExecutionMode. (Closed)
Patch Set: self-review Created 4 years, 1 month 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/post_task.h
diff --git a/base/task_scheduler/post_task.h b/base/task_scheduler/post_task.h
index a7a2114efb7b30f07e8ed3d2ede92de169327514..6e8d002b48f897ffa634eaec52fea952d88a6f93 100644
--- a/base/task_scheduler/post_task.h
+++ b/base/task_scheduler/post_task.h
@@ -9,6 +9,8 @@
#include "base/callback_forward.h"
#include "base/location.h"
#include "base/memory/ref_counted.h"
+#include "base/sequenced_task_runner.h"
+#include "base/single_thread_task_runner.h"
#include "base/task_runner.h"
#include "base/task_scheduler/task_traits.h"
@@ -32,18 +34,17 @@ namespace base {
// Bind(...));
//
// To post tasks that must run in sequence:
-// scoped_refptr<TaskRunner> task_runner = CreateTaskRunnerWithTraits(
-// TaskTraits(), ExecutionMode::SEQUENCED);
+// scoped_refptr<SequencedTaskRunner> task_runner =
+// CreateSequencedTaskRunnerWithTraits(TaskTraits());
// task_runner.PostTask(FROM_HERE, Bind(...));
// task_runner.PostTask(FROM_HERE, Bind(...));
//
// To post file I/O tasks that must run in sequence and can be skipped on
// shutdown:
-// scoped_refptr<TaskRunner> task_runner =
-// CreateTaskRunnerWithTraits(
+// scoped_refptr<SequencedTaskRunner> task_runner =
+// CreateSequencedTaskRunnerWithTraits(
// TaskTraits().WithFileIO().WithShutdownBehavior(
-// TaskShutdownBehavior::SKIP_ON_SHUTDOWN),
-// ExecutionMode::SEQUENCED);
+// TaskShutdownBehavior::SKIP_ON_SHUTDOWN));
// task_runner.PostTask(FROM_HERE, Bind(...));
// task_runner.PostTask(FROM_HERE, Bind(...));
//
@@ -85,11 +86,26 @@ BASE_EXPORT void PostTaskWithTraitsAndReply(
const Closure& task,
const Closure& reply);
-// Returns a TaskRunner whose PostTask invocations will result in scheduling
-// tasks using |traits| which will be executed according to |execution_mode|.
+// Returns a TaskRunner whose PostTask invocations result in scheduling tasks
+// using |traits|. Tasks may run in any order and in parallel.
BASE_EXPORT scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits(
- TaskTraits traits,
- ExecutionMode execution_mode);
+ const TaskTraits& traits);
+
+// Returns a SequencedTaskRunner whose PostTask invocations result in scheduling
+// tasks using |traits|. Tasks run one at a time in posting order.
+BASE_EXPORT scoped_refptr<SequencedTaskRunner>
+CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits);
+
+// Returns a SingleThreadTaskRunner whose PostTask invocations result in
+// scheduling tasks using |traits|. Tasks run on a single thread in posting
+// order.
+//
+// If all you need is to make sure that tasks don't run concurrently (e.g.
+// because they access a data structure which is not thread-safe), use
+// CreateSequencedTaskRunnerWithTraits(). Do NOT use this unless you share data
+// across tasks using thread-local storage or you rely on a thread-affine API.
gab 2016/10/31 19:10:11 The last sentence is slightly too strict given wha
fdoray 2016/10/31 19:44:51 Done.
+BASE_EXPORT scoped_refptr<SingleThreadTaskRunner>
+CreateSingleThreadTaskRunnerWithTraits(const TaskTraits& traits);
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698