use gdt_cpus::{
AppliedPriority, ThreadPriority, demote_thread_from_realtime, priority_capabilities,
promote_thread_to_realtime, set_thread_priority,
};
use std::time::Duration;
const LEVELS: [ThreadPriority; 7] = [
ThreadPriority::Background,
ThreadPriority::Lowest,
ThreadPriority::BelowNormal,
ThreadPriority::Normal,
ThreadPriority::AboveNormal,
ThreadPriority::Highest,
ThreadPriority::TimeCritical,
];
fn main() {
let caps = priority_capabilities();
println!("priority_capabilities() - what this process can currently get:");
println!(" effective ranks : {:?}", caps.effective_rank);
println!(" distinct levels : {}/7", caps.distinct_levels());
println!(" row detail : concrete scheduler API and value applied below");
if caps.distinct(ThreadPriority::Highest, ThreadPriority::Normal) {
println!(" verdict : the full ladder is effectively distinct here.");
} else {
println!(" verdict : Highest == Normal - a render thread will NOT");
println!(" outrank your workers (no privilege / no rtkit).");
}
println!("\nset_thread_priority() - what each request actually does:");
for level in LEVELS {
let applied: gdt_cpus::Result<AppliedPriority> =
std::thread::spawn(move || set_thread_priority(level))
.join()
.unwrap();
match applied {
Ok(a) => println!(" {a}"),
Err(e) => println!(" {level}: error: {e}"),
}
}
println!("\npromote_thread_to_realtime() - the consent API:");
std::thread::spawn(|| {
match promote_thread_to_realtime(Duration::from_millis(1)) {
Ok(a) => {
println!(" promoted : {a}");
match demote_thread_from_realtime() {
Ok(()) => println!(" demoted : back to normal scheduling"),
Err(e) => println!(" demote failed: {e}"),
}
}
Err(e) => println!(" denied : {e}"),
}
})
.join()
.unwrap();
}