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 #ifndef BASE_TASK_SCHEDULER_TASK_TRAITS_H_ | 5 #ifndef BASE_TASK_SCHEDULER_TASK_TRAITS_H_ |
6 #define BASE_TASK_SCHEDULER_TASK_TRAITS_H_ | 6 #define BASE_TASK_SCHEDULER_TASK_TRAITS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <iosfwd> | 10 #include <iosfwd> |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 template <class... ArgTypes, | 150 template <class... ArgTypes, |
151 class CheckArgumentsAreValid = internal::InitTypes< | 151 class CheckArgumentsAreValid = internal::InitTypes< |
152 decltype(ValidTrait(std::declval<ArgTypes>()))...>> | 152 decltype(ValidTrait(std::declval<ArgTypes>()))...>> |
153 constexpr TaskTraits(ArgTypes... args) | 153 constexpr TaskTraits(ArgTypes... args) |
154 : priority_set_explicitly_( | 154 : priority_set_explicitly_( |
155 internal::HasArgOfType<base::TaskPriority, ArgTypes...>::value), | 155 internal::HasArgOfType<base::TaskPriority, ArgTypes...>::value), |
156 priority_(internal::GetValueFromArgList( | 156 priority_(internal::GetValueFromArgList( |
157 internal::EnumArgGetter<base::TaskPriority, | 157 internal::EnumArgGetter<base::TaskPriority, |
158 base::TaskPriority::USER_VISIBLE>(), | 158 base::TaskPriority::USER_VISIBLE>(), |
159 args...)), | 159 args...)), |
| 160 shutdown_behavior_set_explicitly_( |
| 161 internal::HasArgOfType<base::TaskShutdownBehavior, |
| 162 ArgTypes...>::value), |
160 shutdown_behavior_(internal::GetValueFromArgList( | 163 shutdown_behavior_(internal::GetValueFromArgList( |
161 internal::EnumArgGetter< | 164 internal::EnumArgGetter< |
162 base::TaskShutdownBehavior, | 165 base::TaskShutdownBehavior, |
163 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN>(), | 166 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN>(), |
164 args...)), | 167 args...)), |
165 may_block_(internal::GetValueFromArgList( | 168 may_block_(internal::GetValueFromArgList( |
166 internal::BooleanArgGetter<base::MayBlock>(), | 169 internal::BooleanArgGetter<base::MayBlock>(), |
167 args...)), | 170 args...)), |
168 with_base_sync_primitives_(internal::GetValueFromArgList( | 171 with_base_sync_primitives_(internal::GetValueFromArgList( |
169 internal::BooleanArgGetter<base::WithBaseSyncPrimitives>(), | 172 internal::BooleanArgGetter<base::WithBaseSyncPrimitives>(), |
170 args...)) {} | 173 args...)) {} |
171 | 174 |
172 constexpr TaskTraits(const TaskTraits& other) = default; | 175 constexpr TaskTraits(const TaskTraits& other) = default; |
173 TaskTraits& operator=(const TaskTraits& other) = default; | 176 TaskTraits& operator=(const TaskTraits& other) = default; |
174 | 177 |
| 178 // Returns TaskTraits constructed by combining |left| and |right|. If a trait |
| 179 // is specified in both |left| and |right|, the returned TaskTraits will have |
| 180 // the value from |right|. |
| 181 static constexpr TaskTraits Override(const TaskTraits& left, |
| 182 const TaskTraits& right) { |
| 183 return TaskTraits(left, right); |
| 184 } |
| 185 |
175 // Deprecated. Prefer constexpr construction to builder paradigm as | 186 // Deprecated. Prefer constexpr construction to builder paradigm as |
176 // documented above. | 187 // documented above. |
177 // TODO(fdoray): Remove these methods. https://crbug.com/713683 | 188 // TODO(fdoray): Remove these methods. https://crbug.com/713683 |
178 TaskTraits& WithPriority(TaskPriority priority); | 189 TaskTraits& WithPriority(TaskPriority priority); |
179 TaskTraits& WithShutdownBehavior(TaskShutdownBehavior shutdown_behavior); | 190 TaskTraits& WithShutdownBehavior(TaskShutdownBehavior shutdown_behavior); |
180 TaskTraits& MayBlock(); | 191 TaskTraits& MayBlock(); |
181 TaskTraits& WithBaseSyncPrimitives(); | 192 TaskTraits& WithBaseSyncPrimitives(); |
182 | 193 |
183 // Returns true if the priority was set explicitly. | 194 // Returns true if the priority was set explicitly. |
184 constexpr bool priority_set_explicitly() const { | 195 constexpr bool priority_set_explicitly() const { |
185 return priority_set_explicitly_; | 196 return priority_set_explicitly_; |
186 } | 197 } |
187 | 198 |
188 // Returns the priority of tasks with these traits. | 199 // Returns the priority of tasks with these traits. |
189 constexpr TaskPriority priority() const { return priority_; } | 200 constexpr TaskPriority priority() const { return priority_; } |
190 | 201 |
| 202 // Returns true if the shutdown behavior was set explicitly. |
| 203 constexpr bool shutdown_behavior_set_explicitly() const { |
| 204 return shutdown_behavior_set_explicitly_; |
| 205 } |
| 206 |
191 // Returns the shutdown behavior of tasks with these traits. | 207 // Returns the shutdown behavior of tasks with these traits. |
192 constexpr TaskShutdownBehavior shutdown_behavior() const { | 208 constexpr TaskShutdownBehavior shutdown_behavior() const { |
193 return shutdown_behavior_; | 209 return shutdown_behavior_; |
194 } | 210 } |
195 | 211 |
196 // Returns true if tasks with these traits may block. | 212 // Returns true if tasks with these traits may block. |
197 constexpr bool may_block() const { return may_block_; } | 213 constexpr bool may_block() const { return may_block_; } |
198 | 214 |
199 // Returns true if tasks with these traits may use base/ sync primitives. | 215 // Returns true if tasks with these traits may use base/ sync primitives. |
200 constexpr bool with_base_sync_primitives() const { | 216 constexpr bool with_base_sync_primitives() const { |
201 return with_base_sync_primitives_; | 217 return with_base_sync_primitives_; |
202 } | 218 } |
203 | 219 |
204 private: | 220 private: |
| 221 constexpr TaskTraits(const TaskTraits& left, const TaskTraits& right) |
| 222 : priority_set_explicitly_(left.priority_set_explicitly_ || |
| 223 right.priority_set_explicitly_), |
| 224 priority_(right.priority_set_explicitly_ ? right.priority_ |
| 225 : left.priority_), |
| 226 shutdown_behavior_set_explicitly_( |
| 227 left.shutdown_behavior_set_explicitly_ || |
| 228 right.shutdown_behavior_set_explicitly_), |
| 229 shutdown_behavior_(right.shutdown_behavior_set_explicitly_ |
| 230 ? right.shutdown_behavior_ |
| 231 : left.shutdown_behavior_), |
| 232 may_block_(left.may_block_ || right.may_block_), |
| 233 with_base_sync_primitives_(left.with_base_sync_primitives_ || |
| 234 right.with_base_sync_primitives_) {} |
| 235 |
205 // TODO(fdoray): Make these const after refactoring away deprecated builder | 236 // TODO(fdoray): Make these const after refactoring away deprecated builder |
206 // pattern. | 237 // pattern. |
207 bool priority_set_explicitly_; | 238 bool priority_set_explicitly_; |
208 TaskPriority priority_; | 239 TaskPriority priority_; |
| 240 bool shutdown_behavior_set_explicitly_; |
209 TaskShutdownBehavior shutdown_behavior_; | 241 TaskShutdownBehavior shutdown_behavior_; |
210 bool may_block_; | 242 bool may_block_; |
211 bool with_base_sync_primitives_; | 243 bool with_base_sync_primitives_; |
212 }; | 244 }; |
213 | 245 |
214 // Returns string literals for the enums defined in this file. These methods | 246 // Returns string literals for the enums defined in this file. These methods |
215 // should only be used for tracing and debugging. | 247 // should only be used for tracing and debugging. |
216 BASE_EXPORT const char* TaskPriorityToString(TaskPriority task_priority); | 248 BASE_EXPORT const char* TaskPriorityToString(TaskPriority task_priority); |
217 BASE_EXPORT const char* TaskShutdownBehaviorToString( | 249 BASE_EXPORT const char* TaskShutdownBehaviorToString( |
218 TaskShutdownBehavior task_priority); | 250 TaskShutdownBehavior task_priority); |
219 | 251 |
220 // Stream operators so that the enums defined in this file can be used in | 252 // Stream operators so that the enums defined in this file can be used in |
221 // DCHECK and EXPECT statements. | 253 // DCHECK and EXPECT statements. |
222 BASE_EXPORT std::ostream& operator<<(std::ostream& os, | 254 BASE_EXPORT std::ostream& operator<<(std::ostream& os, |
223 const TaskPriority& shutdown_behavior); | 255 const TaskPriority& shutdown_behavior); |
224 BASE_EXPORT std::ostream& operator<<( | 256 BASE_EXPORT std::ostream& operator<<( |
225 std::ostream& os, | 257 std::ostream& os, |
226 const TaskShutdownBehavior& shutdown_behavior); | 258 const TaskShutdownBehavior& shutdown_behavior); |
227 | 259 |
228 } // namespace base | 260 } // namespace base |
229 | 261 |
230 #endif // BASE_TASK_SCHEDULER_TASK_TRAITS_H_ | 262 #endif // BASE_TASK_SCHEDULER_TASK_TRAITS_H_ |
OLD | NEW |