diff --git a/miner/src/cacluate.rs b/miner/src/cacluate.rs index fd7c0c5..b5abda0 100644 --- a/miner/src/cacluate.rs +++ b/miner/src/cacluate.rs @@ -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(( diff --git a/miner/src/main.rs b/miner/src/main.rs index a687659..4e66cb7 100644 --- a/miner/src/main.rs +++ b/miner/src/main.rs @@ -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); }