Skip to content

Commit 91f4fbe

Browse files
committed
Improve comments
1 parent ca6461c commit 91f4fbe

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

crates/stdx/src/thread.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ impl Builder {
6262

6363
pub struct JoinHandle<T = ()> {
6464
// `inner` is an `Option` so that we can
65-
// take ownership of the contained `JoinHandle`
66-
// in the `Drop` impl below.
65+
// take ownership of the contained `JoinHandle`.
6766
inner: Option<jod_thread::JoinHandle<T>>,
6867
allow_leak: bool,
6968
}
@@ -93,8 +92,8 @@ impl<T> fmt::Debug for JoinHandle<T> {
9392
}
9493

9594
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
95+
// Please maintain order from least to most priority for the derived `Ord` impl.
9696
pub enum QoSClass {
97-
// Maintain order in priority from least to most.
9897
Background,
9998
Utility,
10099
UserInitiated,
@@ -132,9 +131,8 @@ pub fn set_current_thread_qos_class(class: QoSClass) {
132131
// due to a previous call to a function such as `pthread_setschedparam`
133132
// which is incompatible with QoS.
134133
//
135-
// Let’s just panic here because rust-analyzer as a system
136-
// should have the property that QoS is used consistently
137-
// instead of old manual scheduling management APIs.
134+
// Panic instead of returning an error
135+
// to maintain the invariant that we only use QoS APIs.
138136
panic!("tried to set QoS of thread which has opted out of QoS (os error {errno})")
139137
}
140138

@@ -187,8 +185,14 @@ pub fn get_current_thread_qos_class() -> Option<QoSClass> {
187185
libc::qos_class_t::QOS_CLASS_DEFAULT => None, // QoS has never been set
188186
libc::qos_class_t::QOS_CLASS_UTILITY => Some(QoSClass::Utility),
189187
libc::qos_class_t::QOS_CLASS_BACKGROUND => Some(QoSClass::Background),
188+
190189
libc::qos_class_t::QOS_CLASS_UNSPECIFIED => {
191-
// We panic here because rust-analyzer should never use
190+
// Using manual scheduling APIs causes threads to “opt out” of QoS.
191+
// At this point they become incompatible with QoS,
192+
// and as such have the “unspecified” QoS class.
193+
//
194+
// Panic instead of returning an error
195+
// to maintain the invariant that we only use QoS APIs.
192196
panic!("tried to get QoS of thread which has opted out of QoS")
193197
}
194198
}

0 commit comments

Comments
 (0)