mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 13:23:25 +00:00
upstream stdx changes
This commit is contained in:
parent
2261e4e892
commit
428ee50540
11 changed files with 131 additions and 97 deletions
|
|
@ -1,9 +1,9 @@
|
|||
//! An opaque façade around platform-specific QoS APIs.
|
||||
//! An opaque façade around platform-specific `QoS` APIs.
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
// Please maintain order from least to most priority for the derived `Ord` impl.
|
||||
pub enum ThreadIntent {
|
||||
/// Any thread which does work that isn’t in the critical path of the user typing
|
||||
/// Any thread which does work that isn't in the critical path of the user typing
|
||||
/// (e.g. processing Go To Definition).
|
||||
Worker,
|
||||
|
||||
|
|
@ -34,6 +34,7 @@ use imp::QoSClass;
|
|||
|
||||
const IS_QOS_AVAILABLE: bool = imp::IS_QOS_AVAILABLE;
|
||||
|
||||
#[expect(clippy::semicolon_if_nothing_returned, reason = "thin wrapper")]
|
||||
fn set_current_thread_qos_class(class: QoSClass) {
|
||||
imp::set_current_thread_qos_class(class)
|
||||
}
|
||||
|
|
@ -63,7 +64,7 @@ mod imp {
|
|||
///
|
||||
/// * **You do not care about how long it takes for work to finish.**
|
||||
/// * **You do not care about work being deferred temporarily.**
|
||||
/// (e.g. if the device’s battery is in a critical state)
|
||||
/// (e.g. if the device's battery is in a critical state)
|
||||
///
|
||||
/// Examples:
|
||||
///
|
||||
|
|
@ -84,7 +85,7 @@ mod imp {
|
|||
/// All other work is prioritized over background tasks.
|
||||
Background,
|
||||
|
||||
/// TLDR: tasks that don’t block using your app
|
||||
/// TLDR: tasks that don't block using your app
|
||||
///
|
||||
/// Contract:
|
||||
///
|
||||
|
|
@ -110,7 +111,7 @@ mod imp {
|
|||
/// for tasks using this class.
|
||||
///
|
||||
/// This QoS class provides a balance between
|
||||
/// performance, responsiveness and efficiency.
|
||||
/// performance, responsiveness, and efficiency.
|
||||
Utility,
|
||||
|
||||
/// TLDR: tasks that block using your app
|
||||
|
|
@ -126,10 +127,10 @@ mod imp {
|
|||
/// * in a video editor:
|
||||
/// opening a saved project
|
||||
/// * in a browser:
|
||||
/// loading a list of the user’s bookmarks and top sites
|
||||
/// loading a list of the user's bookmarks and top sites
|
||||
/// when a new tab is created
|
||||
/// * in a collaborative word processor:
|
||||
/// running a search on the document’s content
|
||||
/// running a search on the document's content
|
||||
///
|
||||
/// Use this QoS class for tasks which were initiated by the user
|
||||
/// and block the usage of your app while they are in progress.
|
||||
|
|
@ -208,7 +209,7 @@ mod imp {
|
|||
}
|
||||
|
||||
_ => {
|
||||
// `pthread_set_qos_class_self_np`’s documentation
|
||||
// `pthread_set_qos_class_self_np`'s documentation
|
||||
// does not mention any other errors.
|
||||
unreachable!("`pthread_set_qos_class_self_np` returned unexpected error {errno}")
|
||||
}
|
||||
|
|
@ -223,7 +224,7 @@ mod imp {
|
|||
};
|
||||
|
||||
if code != 0 {
|
||||
// `pthread_get_qos_class_np`’s documentation states that
|
||||
// `pthread_get_qos_class_np`'s documentation states that
|
||||
// an error value is placed into errno if the return code is not zero.
|
||||
// However, it never states what errors are possible.
|
||||
// Inspecting the source[0] shows that, as of this writing, it always returns zero.
|
||||
|
|
|
|||
|
|
@ -38,7 +38,11 @@ struct Job {
|
|||
}
|
||||
|
||||
impl Pool {
|
||||
pub fn new(threads: usize) -> Pool {
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if job panics
|
||||
#[must_use]
|
||||
pub fn new(threads: usize) -> Self {
|
||||
const STACK_SIZE: usize = 8 * 1024 * 1024;
|
||||
const INITIAL_INTENT: ThreadIntent = ThreadIntent::Worker;
|
||||
|
||||
|
|
@ -63,7 +67,7 @@ impl Pool {
|
|||
}
|
||||
extant_tasks.fetch_add(1, Ordering::SeqCst);
|
||||
// discard the panic, we should've logged the backtrace already
|
||||
_ = panic::catch_unwind(job.f);
|
||||
drop(panic::catch_unwind(job.f));
|
||||
extant_tasks.fetch_sub(1, Ordering::SeqCst);
|
||||
}
|
||||
}
|
||||
|
|
@ -73,9 +77,12 @@ impl Pool {
|
|||
handles.push(handle);
|
||||
}
|
||||
|
||||
Pool { _handles: handles.into_boxed_slice(), extant_tasks, job_sender }
|
||||
Self { _handles: handles.into_boxed_slice(), extant_tasks, job_sender }
|
||||
}
|
||||
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if job panics
|
||||
pub fn spawn<F>(&self, intent: ThreadIntent, f: F)
|
||||
where
|
||||
F: FnOnce() + Send + UnwindSafe + 'static,
|
||||
|
|
@ -84,14 +91,20 @@ impl Pool {
|
|||
if cfg!(debug_assertions) {
|
||||
intent.assert_is_used_on_current_thread();
|
||||
}
|
||||
f()
|
||||
f();
|
||||
});
|
||||
|
||||
let job = Job { requested_intent: intent, f };
|
||||
self.job_sender.send(job).unwrap();
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn len(&self) -> usize {
|
||||
self.extant_tasks.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue