Skip to content

Commit bb02ae7

Browse files
committed
Add doc comments for QoSClass
1 parent 91f4fbe commit bb02ae7

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

crates/stdx/src/thread.rs

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,116 @@ impl<T> fmt::Debug for JoinHandle<T> {
9494
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
9595
// Please maintain order from least to most priority for the derived `Ord` impl.
9696
pub enum QoSClass {
97+
// Documentation adapted from https://github.com/apple-oss-distributions/libpthread/blob/67e155c94093be9a204b69637d198eceff2c7c46/include/sys/qos.h#L55
98+
//
99+
/// TLDR: invisible maintenance tasks
100+
///
101+
/// Contract:
102+
///
103+
/// * **You do not care about how long it takes for work to finish.**
104+
/// * **You do not care about work being deferred temporarily.**
105+
/// (e.g. if the device’s battery is in a critical state)
106+
///
107+
/// Examples:
108+
///
109+
/// * in a video editor:
110+
/// creating periodic backups of project files
111+
/// * in a browser:
112+
/// cleaning up cached sites which have not been accessed in a long time
113+
/// * in a collaborative word processor:
114+
/// creating a searchable index of all documents
115+
///
116+
/// Use this QoS class for background tasks
117+
/// which the user did not initiate themselves
118+
/// and which are invisible to the user.
119+
/// It is expected that this work will take significant time to complete:
120+
/// minutes or even hours.
121+
///
122+
/// This QoS class provides the most energy and thermally-efficient execution possible.
123+
/// All other work is prioritized over background tasks.
97124
Background,
125+
126+
/// TLDR: tasks that don’t block using your app
127+
///
128+
/// Contract:
129+
///
130+
/// * **Your app remains useful even as the task is executing.**
131+
///
132+
/// Examples:
133+
///
134+
/// * in a video editor:
135+
/// exporting a video to disk –
136+
/// the user can still work on the timeline
137+
/// * in a browser:
138+
/// automatically extracting a downloaded zip file –
139+
/// the user can still switch tabs
140+
/// * in a collaborative word processor:
141+
/// downloading images embedded in a document –
142+
/// the user can still make edits
143+
///
144+
/// Use this QoS class for tasks which
145+
/// may or may not be initiated by the user,
146+
/// but whose result is visible.
147+
/// It is expected that this work will take a few seconds to a few minutes.
148+
/// Typically your app will include a progress bar
149+
/// for tasks using this class.
150+
///
151+
/// This QoS class provides a balance between
152+
/// performance, responsiveness and efficiency.
98153
Utility,
154+
155+
/// TLDR: tasks that block using your app
156+
///
157+
/// Contract:
158+
///
159+
/// * **You need this work to complete
160+
/// before the user can keep interacting with your app.**
161+
/// * **Your work will not take more than a few seconds to complete.**
162+
///
163+
/// Examples:
164+
///
165+
/// * in a video editor:
166+
/// opening a saved project
167+
/// * in a browser:
168+
/// loading a list of the user’s bookmarks and top sites
169+
/// when a new tab is created
170+
/// * in a collaborative word processor:
171+
/// running a search on the document’s content
172+
///
173+
/// Use this QoS class for tasks which were initiated by the user
174+
/// and block the usage of your app while they are in progress.
175+
/// It is expected that this work will take a few seconds or less to complete;
176+
/// not long enough to cause the user to switch to something else.
177+
/// Your app will likely indicate progress on these tasks
178+
/// through the display of placeholder content or modals.
179+
///
180+
/// This QoS class is not energy-efficient.
181+
/// Rather, it provides responsiveness
182+
/// by prioritizing work above other tasks on the system
183+
/// except for critical user-interactive work.
99184
UserInitiated,
185+
186+
/// TLDR: render loops and nothing else
187+
///
188+
/// Contract:
189+
///
190+
/// * **You absolutely need this work to complete immediately
191+
/// or your app will appear to freeze.**
192+
/// * **Your work will always complete virtually instantaneously.**
193+
///
194+
/// Examples:
195+
///
196+
/// * the main thread in a GUI application
197+
/// * the update & render loop in a game
198+
/// * a secondary thread which progresses an animation
199+
///
200+
/// Use this QoS class for any work which, if delayed,
201+
/// will make your user interface unresponsive.
202+
/// It is expected that this work will be virtually instantaneous.
203+
///
204+
/// This QoS class is not energy-efficient.
205+
/// Specifying this class is a request to run with
206+
/// nearly all available system CPU and I/O bandwidth even under contention.
100207
UserInteractive,
101208
}
102209

0 commit comments

Comments
 (0)