OLD | NEW |
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" | |
13 | 12 |
14 namespace base { | 13 namespace base { |
15 | 14 |
16 // Do not rely on defaults hard-coded below beyond the guarantees described in | 15 TaskTraits::TaskTraits() = default; |
17 // the header; anything else is subject to change. Tasks should explicitly | |
18 // request defaults if the behavior is critical to the task. | |
19 TaskTraits::TaskTraits() | |
20 : may_block_(false), | |
21 with_base_sync_primitives_(false), | |
22 priority_(internal::GetTaskPriorityForCurrentThread()), | |
23 shutdown_behavior_(TaskShutdownBehavior::SKIP_ON_SHUTDOWN) {} | |
24 | |
25 TaskTraits::~TaskTraits() = default; | 16 TaskTraits::~TaskTraits() = default; |
26 | 17 |
27 TaskTraits& TaskTraits::MayBlock() { | 18 TaskTraits& TaskTraits::MayBlock() { |
28 may_block_ = true; | 19 may_block_ = true; |
29 return *this; | 20 return *this; |
30 } | 21 } |
31 | 22 |
32 TaskTraits& TaskTraits::WithBaseSyncPrimitives() { | 23 TaskTraits& TaskTraits::WithBaseSyncPrimitives() { |
33 with_base_sync_primitives_ = true; | 24 with_base_sync_primitives_ = true; |
34 return *this; | 25 return *this; |
35 } | 26 } |
36 | 27 |
37 TaskTraits& TaskTraits::WithPriority(TaskPriority priority) { | 28 TaskTraits& TaskTraits::WithPriority(TaskPriority priority) { |
| 29 priority_set_explicitly_ = true; |
38 priority_ = priority; | 30 priority_ = priority; |
39 return *this; | 31 return *this; |
40 } | 32 } |
41 | 33 |
42 TaskTraits& TaskTraits::WithShutdownBehavior( | 34 TaskTraits& TaskTraits::WithShutdownBehavior( |
43 TaskShutdownBehavior shutdown_behavior) { | 35 TaskShutdownBehavior shutdown_behavior) { |
44 shutdown_behavior_ = shutdown_behavior; | 36 shutdown_behavior_ = shutdown_behavior; |
45 return *this; | 37 return *this; |
46 } | 38 } |
47 | 39 |
(...skipping 29 matching lines...) Expand all Loading... |
77 return os; | 69 return os; |
78 } | 70 } |
79 | 71 |
80 std::ostream& operator<<(std::ostream& os, | 72 std::ostream& operator<<(std::ostream& os, |
81 const TaskShutdownBehavior& shutdown_behavior) { | 73 const TaskShutdownBehavior& shutdown_behavior) { |
82 os << TaskShutdownBehaviorToString(shutdown_behavior); | 74 os << TaskShutdownBehaviorToString(shutdown_behavior); |
83 return os; | 75 return os; |
84 } | 76 } |
85 | 77 |
86 } // namespace base | 78 } // namespace base |
OLD | NEW |