Improve comments

This commit is contained in:
Luna Razzaghipour 2023-05-21 02:02:21 +10:00
parent ca6461c143
commit 91f4fbe596
No known key found for this signature in database

View File

@ -62,8 +62,7 @@ impl Builder {
pub struct JoinHandle<T = ()> { pub struct JoinHandle<T = ()> {
// `inner` is an `Option` so that we can // `inner` is an `Option` so that we can
// take ownership of the contained `JoinHandle` // take ownership of the contained `JoinHandle`.
// in the `Drop` impl below.
inner: Option<jod_thread::JoinHandle<T>>, inner: Option<jod_thread::JoinHandle<T>>,
allow_leak: bool, allow_leak: bool,
} }
@ -93,8 +92,8 @@ impl<T> fmt::Debug for JoinHandle<T> {
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
// Please maintain order from least to most priority for the derived `Ord` impl.
pub enum QoSClass { pub enum QoSClass {
// Maintain order in priority from least to most.
Background, Background,
Utility, Utility,
UserInitiated, UserInitiated,
@ -132,9 +131,8 @@ pub fn set_current_thread_qos_class(class: QoSClass) {
// due to a previous call to a function such as `pthread_setschedparam` // due to a previous call to a function such as `pthread_setschedparam`
// which is incompatible with QoS. // which is incompatible with QoS.
// //
// Lets just panic here because rust-analyzer as a system // Panic instead of returning an error
// should have the property that QoS is used consistently // to maintain the invariant that we only use QoS APIs.
// instead of old manual scheduling management APIs.
panic!("tried to set QoS of thread which has opted out of QoS (os error {errno})") panic!("tried to set QoS of thread which has opted out of QoS (os error {errno})")
} }
@ -187,8 +185,14 @@ pub fn get_current_thread_qos_class() -> Option<QoSClass> {
libc::qos_class_t::QOS_CLASS_DEFAULT => None, // QoS has never been set libc::qos_class_t::QOS_CLASS_DEFAULT => None, // QoS has never been set
libc::qos_class_t::QOS_CLASS_UTILITY => Some(QoSClass::Utility), libc::qos_class_t::QOS_CLASS_UTILITY => Some(QoSClass::Utility),
libc::qos_class_t::QOS_CLASS_BACKGROUND => Some(QoSClass::Background), libc::qos_class_t::QOS_CLASS_BACKGROUND => Some(QoSClass::Background),
libc::qos_class_t::QOS_CLASS_UNSPECIFIED => { libc::qos_class_t::QOS_CLASS_UNSPECIFIED => {
// We panic here because rust-analyzer should never use // Using manual scheduling APIs causes threads to “opt out” of QoS.
// At this point they become incompatible with QoS,
// and as such have the “unspecified” QoS class.
//
// Panic instead of returning an error
// to maintain the invariant that we only use QoS APIs.
panic!("tried to get QoS of thread which has opted out of QoS") panic!("tried to get QoS of thread which has opted out of QoS")
} }
} }