Implement custom QoS-aware thread pool

This code replaces the thread pool implementation we were using
previously (from the `threadpool` crate). By making the thread pool
aware of QoS, each job spawned on the thread pool can have a different
QoS class.

This commit also replaces every QoS class used previously with Default
as a temporary measure so that each usage can be chosen deliberately.
This commit is contained in:
Luna Razzaghipour 2023-05-25 17:04:51 +10:00
parent f6e3a87bf9
commit 2924fd2213
No known key found for this signature in database
14 changed files with 184 additions and 93 deletions

View file

@ -13,6 +13,9 @@
use std::fmt;
mod pool;
pub use pool::Pool;
pub fn spawn<F, T>(qos_class: QoSClass, f: F) -> JoinHandle<T>
where
F: FnOnce() -> T,
@ -152,6 +155,8 @@ pub enum QoSClass {
/// performance, responsiveness and efficiency.
Utility,
Default,
/// TLDR: tasks that block using your app
///
/// Contract:
@ -229,6 +234,7 @@ mod imp {
let c = match class {
QoSClass::UserInteractive => libc::qos_class_t::QOS_CLASS_USER_INTERACTIVE,
QoSClass::UserInitiated => libc::qos_class_t::QOS_CLASS_USER_INITIATED,
QoSClass::Default => libc::qos_class_t::QOS_CLASS_DEFAULT,
QoSClass::Utility => libc::qos_class_t::QOS_CLASS_UTILITY,
QoSClass::Background => libc::qos_class_t::QOS_CLASS_BACKGROUND,
};