From bc7e5edfc49e170973b33449da7ec2b0132fe2ff Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 24 Jun 2024 13:18:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E4=B8=AA=E8=AE=BE=E7=BD=AE=E9=AB=98?= =?UTF-8?q?=E4=BC=98=E5=85=88=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miner/src/cacluate.rs | 2 ++ miner/src/main.rs | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) 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); }