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

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

Issue 1897483002: TaskScheduler: Add static_assert in TaskTraits::operator==. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@6_threadpool
Patch Set: add static_assert message Created 4 years, 8 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
8
7 #include <ostream> 9 #include <ostream>
8 10
9 namespace base { 11 namespace base {
10 12
11 // Do not rely on defaults hard-coded below beyond the guarantees described in 13 // Do not rely on defaults hard-coded below beyond the guarantees described in
12 // the header; anything else is subject to change. Tasks should explicitly 14 // the header; anything else is subject to change. Tasks should explicitly
13 // request defaults if the behavior is critical to the task. 15 // request defaults if the behavior is critical to the task.
14 TaskTraits::TaskTraits() 16 TaskTraits::TaskTraits()
15 : with_file_io_(false), 17 : with_file_io_(false),
16 priority_(TaskPriority::BACKGROUND), 18 priority_(TaskPriority::BACKGROUND),
(...skipping 11 matching lines...) Expand all
28 return *this; 30 return *this;
29 } 31 }
30 32
31 TaskTraits& TaskTraits::WithShutdownBehavior( 33 TaskTraits& TaskTraits::WithShutdownBehavior(
32 TaskShutdownBehavior shutdown_behavior) { 34 TaskShutdownBehavior shutdown_behavior) {
33 shutdown_behavior_ = shutdown_behavior; 35 shutdown_behavior_ = shutdown_behavior;
34 return *this; 36 return *this;
35 } 37 }
36 38
37 bool TaskTraits::operator==(const TaskTraits& other) const { 39 bool TaskTraits::operator==(const TaskTraits& other) const {
40 static_assert(sizeof(TaskTraits) ==
41 offsetof(TaskTraits, shutdown_behavior_) +
42 sizeof(TaskTraits::shutdown_behavior_),
43 "TaskTraits members changed. Update operator==.");
38 return with_file_io_ == other.with_file_io_ && priority_ == other.priority_ && 44 return with_file_io_ == other.with_file_io_ && priority_ == other.priority_ &&
39 shutdown_behavior_ == other.shutdown_behavior_; 45 shutdown_behavior_ == other.shutdown_behavior_;
40 } 46 }
41 47
42 std::ostream& operator<<(std::ostream& os, const TaskPriority& task_priority) { 48 std::ostream& operator<<(std::ostream& os, const TaskPriority& task_priority) {
43 switch (task_priority) { 49 switch (task_priority) {
44 case TaskPriority::BACKGROUND: 50 case TaskPriority::BACKGROUND:
45 os << "BACKGROUND"; 51 os << "BACKGROUND";
46 break; 52 break;
47 case TaskPriority::USER_VISIBLE: 53 case TaskPriority::USER_VISIBLE:
(...skipping 16 matching lines...) Expand all
64 os << "SKIP_ON_SHUTDOWN"; 70 os << "SKIP_ON_SHUTDOWN";
65 break; 71 break;
66 case TaskShutdownBehavior::BLOCK_SHUTDOWN: 72 case TaskShutdownBehavior::BLOCK_SHUTDOWN:
67 os << "BLOCK_SHUTDOWN"; 73 os << "BLOCK_SHUTDOWN";
68 break; 74 break;
69 } 75 }
70 return os; 76 return os;
71 } 77 }
72 78
73 } // namespace base 79 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698