加个设置高优先级

This commit is contained in:
shenjack 2024-06-24 13:18:10 +08:00
parent d131daed4e
commit bc7e5edfc4
Signed by: shenjack
GPG Key ID: 7B1134A979775551
2 changed files with 20 additions and 1 deletions

View File

@ -214,6 +214,7 @@ pub fn schdule_threads(cli_arg: Command, out_path: PathBuf) {
break;
}
}
break;
} else {
// 如果不是, 则发送一个对应线程 id 的消息
let _ = work_sender.send(Some((latest_speed.0, shared_status.top_id..shared_status.top_id + batch)));
@ -247,6 +248,7 @@ pub fn schdule_threads(cli_arg: Command, out_path: PathBuf) {
break;
}
}
break;
} else {
// 如果没有结束, 则发送一个 batch
let _ = work_sender.send(Some((

View File

@ -123,6 +123,23 @@ pub fn set_process_cores(cores: usize) {
}
}
pub fn set_process_priority_to_high() {
#[cfg(windows)]
unsafe {
use windows_sys::Win32::System::Threading::HIGH_PRIORITY_CLASS;
use windows_sys::Win32::System::Threading::{GetCurrentProcess, SetPriorityClass};
let process = GetCurrentProcess();
match SetPriorityClass(process, HIGH_PRIORITY_CLASS) {
0 => warn!("设置进程优先级为高失败 {}", std::io::Error::last_os_error()),
_ => info!("设置进程优先级为高成功"),
}
}
#[cfg(unix)]
{
warn!("Linux 下不支持设置进程优先级为高 (未实现)")
}
}
fn main() {
let mut cli_arg = Command::parse();
tracing_subscriber::fmt()
@ -160,6 +177,6 @@ fn main() {
}
info!("{}", cli_arg.display_info());
set_process_priority_to_high();
cacluate::start_main(cli_arg, out_path);
}