Chromium Code Reviews| Index: base/task_scheduler/task_traits.h |
| diff --git a/base/task_scheduler/task_traits.h b/base/task_scheduler/task_traits.h |
| index 0fcde2dc989a7ed90c43ced39819fdcc3c91cf99..6eab6848efa097906d705f19a38c5fbbcb5a94f3 100644 |
| --- a/base/task_scheduler/task_traits.h |
| +++ b/base/task_scheduler/task_traits.h |
| @@ -78,9 +78,9 @@ enum class TaskShutdownBehavior { |
| // Describes metadata for a single task or a group of tasks. |
| class BASE_EXPORT TaskTraits { |
| public: |
| - // Constructs a default TaskTraits for tasks with |
| - // (1) no I/O, |
| - // (2) priority inherited from the calling context, and |
| + // Constructs a default TaskTraits for tasks that |
| + // (1) do not make blocking calls |
| + // (2) can inherit their priority from the calling context, and |
| // (3) may block shutdown or be skipped on shutdown. |
| // Tasks that require stricter guarantees and/or know the specific |
| // TaskPriority appropriate for them should highlight those by requesting |
| @@ -90,13 +90,39 @@ class BASE_EXPORT TaskTraits { |
| TaskTraits& operator=(const TaskTraits& other) = default; |
| ~TaskTraits(); |
| - // Allows tasks with these traits to wait on synchronous file I/O. |
| + // Tasks with this trait may block. This includes but is not limited to tasks |
| + // that wait on synchronous file I/O operations: read or write a file from |
| + // disk, a pipe or a socket, rename or delete a file, enumerate files in a |
| + // directory, etc. It is not necessary to use this trait to use locks. For |
| + // tasks that join threads or processes or wait on a waitable event or |
| + // condition variable, see WithSyncPrimitives(). |
| + TaskTraits& MayBlock(); |
| + |
| + // Tasks with this trait are allowed to wait on waitable events and condition |
| + // variables and to join threads and processes. This trait implies MayBlock(). |
|
gab
2016/12/19 20:20:14
s/and to/as well as/
fdoray
2016/12/19 21:22:43
Done.
|
| + // |
| + // In general, you should not use this trait. |
|
gab
2016/12/19 20:20:14
// This trait should generally not be used.
(to
fdoray
2016/12/19 21:22:43
Done.
|
| + // |
|
gab
2016/12/19 20:20:14
Check with jam@ whether we should make this trait
fdoray
2016/12/19 21:22:43
jam@: wdyt?
Note that today, you only need to be
jam
2016/12/19 23:17:34
If it's only used on non UI/IO threads that are me
|
| + // Instead of waiting on a waitable event or a condition variable, put the |
| + // work that you would have done after the wait in a callback and post this |
|
gab
2016/12/19 20:20:14
s/this callback/that callback/
gab
2016/12/19 20:20:14
s/that you would have done/that should happen/
fdoray
2016/12/19 21:22:43
Done.
fdoray
2016/12/19 21:22:43
Done.
|
| + // callback from where you would have signaled the waitable event or condition |
|
gab
2016/12/19 20:20:14
s/you would have signaled the WE or CV/from where
fdoray
2016/12/19 21:22:43
Done.
|
| + // variable. If you need to do something after a bunch of tasks have run, use |
| + // base::BarrierClosure. |
|
gab
2016/12/19 20:20:14
// If something needs to be scheduled after many t
fdoray
2016/12/19 21:22:43
Done.
|
| + // |
| + // On Windows, join processes asynchronously using base::win::ObjectWatcher. |
| + // |
| + // Avoid creating threads. Instead, use |
| + // base::Create(Sequenced|SingleTreaded)TaskRunnerWithTraits(). If you really |
| + // need a thread, make it non-joinable and add cleanup work at the end of the |
|
gab
2016/12/19 20:20:14
If a thread is really needed,
fdoray
2016/12/19 21:22:43
Done.
|
| + // thread's main function (if you use base::Thread, override Cleanup()). |
|
gab
2016/12/19 20:20:14
if using base::Thread, ...
fdoray
2016/12/19 21:22:43
Done.
|
| + TaskTraits& WithSyncPrimitives(); |
| + |
| + // DEPRECATED |
| + // TODO(fdoray): Remove this crbug.com/675660 |
|
gab
2016/12/19 20:20:14
Removes this as part of crbug...
^^^^
fdoray
2016/12/19 21:22:43
Done.
|
| TaskTraits& WithFileIO(); |
| - // Allows tasks with these traits to wait on things other than file I/O. In |
| - // particular, they may wait on a WaitableEvent or a ConditionVariable, join a |
| - // thread or a process, or make a blocking system call that doesn't involve |
| - // interactions with the file system. |
| + // DEPRECATED |
| + // TODO(fdoray): Remove this crbug.com/675660 |
| TaskTraits& WithWait(); |
| // Applies |priority| to tasks with these traits. |
| @@ -105,12 +131,15 @@ class BASE_EXPORT TaskTraits { |
| // Applies |shutdown_behavior| to tasks with these traits. |
| TaskTraits& WithShutdownBehavior(TaskShutdownBehavior shutdown_behavior); |
| - // Returns true if waiting on synchronous file I/O is allowed by these traits. |
| - bool with_file_io() const { return with_file_io_; } |
| + // Returns true if tasks with these traits may block. |
| + bool may_block() const { return may_block_; } |
| + |
| + // Returns true if tasks with these traits may wait on sync primitives. |
| + bool with_sync_primitives() const { return with_sync_primitives_; } |
| - // Returns true if waiting on things other than file I/O is allowed by these |
| - // traits. |
| - bool with_wait() const { return with_wait_; } |
| + // DEPRECATED |
| + // TODO(fdoray): Remove this crbug.com/675660 |
| + bool with_file_io() const { return may_block(); } |
| // Returns the priority of tasks with these traits. |
| TaskPriority priority() const { return priority_; } |
| @@ -119,8 +148,8 @@ class BASE_EXPORT TaskTraits { |
| TaskShutdownBehavior shutdown_behavior() const { return shutdown_behavior_; } |
| private: |
| - bool with_file_io_; |
| - bool with_wait_; |
| + bool may_block_; |
| + bool with_sync_primitives_; |
| TaskPriority priority_; |
| TaskShutdownBehavior shutdown_behavior_; |
| }; |