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

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

Issue 1705253002: TaskScheduler [3/9] Task and Sequence (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s_1_scheduler_lock
Patch Set: static_assert Created 4 years, 10 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
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 #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>
9
10 #include <iosfwd>
11
8 #include "base/base_export.h" 12 #include "base/base_export.h"
9 #include "build/build_config.h" 13 #include "build/build_config.h"
10 14
11 namespace base { 15 namespace base {
12 16
13 using TaskPriorityUnderlyingType = char; 17 namespace internal {
18 using TaskPriorityUnderlyingType = uint8_t;
19 } // namespace internal
14 20
15 // Valid priorities supported by the task scheduler. 21 // Valid priorities supported by the task scheduler. Note: internal algorithms
16 enum class TaskPriority : TaskPriorityUnderlyingType { 22 // depend on priorities being expressed as a continuous zero-based list from
17 // This task affects UI immediately after a user interaction. 23 // lowest to highest priority. Users of this API shouldn't otherwise care about
18 // Example: Generating data shown in the UI immediately after a click. 24 // nor use the underlying values.
19 USER_BLOCKING = 2, 25 enum class TaskPriority : internal::TaskPriorityUnderlyingType {
danakj 2016/03/15 23:16:32 Is there a reason why you need to define the Under
fdoray 2016/03/16 19:11:44 static_cast to int is fine.
26 // This will always be equal to the lowest priority available.
27 LOWEST = 0,
28 // User won't notice if this task takes an arbitrarily long time to complete.
29 BACKGROUND = LOWEST,
20 // This task affects UI or responsiveness of future user interactions. It is 30 // This task affects UI or responsiveness of future user interactions. It is
21 // not an immediate response to a user interaction. 31 // not an immediate response to a user interaction.
22 // Examples: 32 // Examples:
23 // - Updating the UI to reflect progress on a long task. 33 // - Updating the UI to reflect progress on a long task.
24 // - Loading data that might be shown in the UI after a future user 34 // - Loading data that might be shown in the UI after a future user
25 // interaction. 35 // interaction.
26 USER_VISIBLE = 1, 36 USER_VISIBLE,
27 // Everything else (user won't notice if this takes an arbitrarily long time 37 // This task affects UI immediately after a user interaction.
28 // to complete). 38 // Example: Generating data shown in the UI immediately after a click.
29 BACKGROUND = 0, 39 USER_BLOCKING,
40 // This will always be equal to the highest priority available.
41 HIGHEST = USER_BLOCKING,
30 }; 42 };
31 43
32 const TaskPriorityUnderlyingType kNumTaskPriorities = 3; 44 namespace internal {
45 const size_t kNumTaskPriorities =
46 static_cast<TaskPriorityUnderlyingType>(TaskPriority::HIGHEST) + 1;
danakj 2016/03/15 23:16:32 use an enum to put a static const in a header file
fdoray 2016/03/16 19:11:44 I removed this constant. I use static_cast<int>(Ta
47 } // namespace internal
33 48
34 // Valid shutdown behaviors supported by the task scheduler. 49 // Valid shutdown behaviors supported by the task scheduler.
35 enum class TaskShutdownBehavior { 50 enum class TaskShutdownBehavior {
36 // Tasks posted with this mode which have not started executing before 51 // Tasks posted with this mode which have not started executing before
37 // shutdown is initiated will never run. Tasks with this mode running at 52 // shutdown is initiated will never run. Tasks with this mode running at
38 // shutdown will be ignored (the worker thread will not be joined). 53 // shutdown will be ignored (the worker thread will not be joined).
39 // 54 //
40 // This option provides a nice way to post stuff you don't want blocking 55 // This option provides a nice way to post stuff you don't want blocking
41 // shutdown. For example, you might be doing a slow DNS lookup and if it's 56 // shutdown. For example, you might be doing a slow DNS lookup and if it's
42 // blocked on the OS, you may not want to stop shutdown, since the result 57 // blocked on the OS, you may not want to stop shutdown, since the result
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 PARALLEL, 125 PARALLEL,
111 126
112 // Executes one task at a time in posting order. The sequence’s priority is 127 // Executes one task at a time in posting order. The sequence’s priority is
113 // equivalent to the highest priority pending task in the sequence. 128 // equivalent to the highest priority pending task in the sequence.
114 SEQUENCED, 129 SEQUENCED,
115 130
116 // Executes one task at a time on a single thread in posting order. 131 // Executes one task at a time on a single thread in posting order.
117 SINGLE_THREADED, 132 SINGLE_THREADED,
118 }; 133 };
119 134
135 // Pretty Printer for Google Test.
136 void BASE_EXPORT PrintTo(const TaskPriority& task_priority, std::ostream* os);
137
120 } // namespace base 138 } // namespace base
121 139
122 #endif // BASE_TASK_SCHEDULER_TASK_TRAITS_H_ 140 #endif // BASE_TASK_SCHEDULER_TASK_TRAITS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698