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

Side by Side Diff: base/task_scheduler/task_traits.cc

Issue 2590443005: Add TaskTraits::MayBlock and TaskTraits::WithSyncPrimitives. (Closed)
Patch Set: self-review Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/task_scheduler/task_traits.h" 5 #include "base/task_scheduler/task_traits.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <ostream> 9 #include <ostream>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/task_scheduler/scoped_set_task_priority_for_current_thread.h" 12 #include "base/task_scheduler/scoped_set_task_priority_for_current_thread.h"
13 13
14 namespace base { 14 namespace base {
15 15
16 // Do not rely on defaults hard-coded below beyond the guarantees described in 16 // Do not rely on defaults hard-coded below beyond the guarantees described in
17 // the header; anything else is subject to change. Tasks should explicitly 17 // the header; anything else is subject to change. Tasks should explicitly
18 // request defaults if the behavior is critical to the task. 18 // request defaults if the behavior is critical to the task.
gab 2016/12/19 20:20:14 Move this comment and member initialization to mem
fdoray 2016/12/19 21:22:43 Unfortunately, these is an include cycle if I incl
19 TaskTraits::TaskTraits() 19 TaskTraits::TaskTraits()
20 : with_file_io_(false), 20 : may_block_(false),
21 with_wait_(false), 21 with_sync_primitives_(false),
22 priority_(internal::GetTaskPriorityForCurrentThread()), 22 priority_(internal::GetTaskPriorityForCurrentThread()),
23 shutdown_behavior_(TaskShutdownBehavior::SKIP_ON_SHUTDOWN) {} 23 shutdown_behavior_(TaskShutdownBehavior::SKIP_ON_SHUTDOWN) {}
24 24
25 TaskTraits::~TaskTraits() = default; 25 TaskTraits::~TaskTraits() = default;
26 26
27 TaskTraits& TaskTraits::WithFileIO() { 27 TaskTraits& TaskTraits::MayBlock() {
28 with_file_io_ = true; 28 may_block_ = true;
29 return *this; 29 return *this;
30 } 30 }
31 31
32 TaskTraits& TaskTraits::WithSyncPrimitives() {
33 with_sync_primitives_ = true;
34 return *this;
35 }
36
37 TaskTraits& TaskTraits::WithFileIO() {
38 return MayBlock();
39 }
40
32 TaskTraits& TaskTraits::WithWait() { 41 TaskTraits& TaskTraits::WithWait() {
33 with_wait_ = true; 42 return MayBlock().WithSyncPrimitives();
34 return *this;
35 } 43 }
36 44
37 TaskTraits& TaskTraits::WithPriority(TaskPriority priority) { 45 TaskTraits& TaskTraits::WithPriority(TaskPriority priority) {
38 priority_ = priority; 46 priority_ = priority;
39 return *this; 47 return *this;
40 } 48 }
41 49
42 TaskTraits& TaskTraits::WithShutdownBehavior( 50 TaskTraits& TaskTraits::WithShutdownBehavior(
43 TaskShutdownBehavior shutdown_behavior) { 51 TaskShutdownBehavior shutdown_behavior) {
44 shutdown_behavior_ = shutdown_behavior; 52 shutdown_behavior_ = shutdown_behavior;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 return os; 85 return os;
78 } 86 }
79 87
80 std::ostream& operator<<(std::ostream& os, 88 std::ostream& operator<<(std::ostream& os,
81 const TaskShutdownBehavior& shutdown_behavior) { 89 const TaskShutdownBehavior& shutdown_behavior) {
82 os << TaskShutdownBehaviorToString(shutdown_behavior); 90 os << TaskShutdownBehaviorToString(shutdown_behavior);
83 return os; 91 return os;
84 } 92 }
85 93
86 } // namespace base 94 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698