From 19b2eca16d03649ffdd62fb4ad3bacd68b3de09e Mon Sep 17 00:00:00 2001 From: Cyrix126 Date: Mon, 20 May 2024 13:00:19 +0200 Subject: [PATCH] fix windows crasH/instability --- src/helper/p2pool.rs | 8 +++++--- src/helper/xmrig.rs | 16 +++++++++++++++- src/helper/xvb/mod.rs | 18 ++++++++---------- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/helper/p2pool.rs b/src/helper/p2pool.rs index 871c259..7a29e06 100644 --- a/src/helper/p2pool.rs +++ b/src/helper/p2pool.rs @@ -395,7 +395,9 @@ impl Helper { #[inline(never)] // The P2Pool watchdog. Spawns 1 OS thread for reading a PTY (STDOUT+STDERR), and combines the [Child] with a PTY so STDIN actually works. #[allow(clippy::too_many_arguments)] - fn spawn_p2pool_watchdog( + #[allow(clippy::await_holding_lock)] + #[tokio::main] + async fn spawn_p2pool_watchdog( process: Arc>, gui_api: Arc>, pub_api: Arc>, @@ -444,7 +446,7 @@ impl Helper { let output_pub = Arc::clone(&lock!(process).output_pub); let gupax_p2pool_api = Arc::clone(&gupax_p2pool_api); let p2pool_api_c = Arc::clone(&gui_api); - thread::spawn(move || { + tokio::spawn(async move { Self::read_pty_p2pool( output_parse, output_pub, @@ -726,7 +728,7 @@ impl Helper { lock!(gui_api).tick, sleep ); - sleep!(sleep); + tokio::time::sleep(Duration::from_millis(sleep)).await; } else { debug!( "P2Pool Watchdog | END OF LOOP - Tick: [{}/60] Not sleeping!", diff --git a/src/helper/xmrig.rs b/src/helper/xmrig.rs index f932b4b..657c182 100644 --- a/src/helper/xmrig.rs +++ b/src/helper/xmrig.rs @@ -456,6 +456,20 @@ impl Helper { lock!(gui_api).node.clone_from(&lock!(img_xmrig).url); // 5. Loop as watchdog info!("XMRig | Entering watchdog mode... woof!"); + // needs xmrig to be in belownormal priority or else Gupaxx will be in trouble if it does not have enough cpu time. + #[cfg(target_os = "windows")] + std::process::Command::new("cmd") + .args(["/c", "/q", "wmic"]) + .args([ + "process", + "where", + "name='xmrig.exe'", + "CALL", + "setpriority", + "below normal", + ]) + .spawn() + .expect("failure to execute command wmic"); loop { // Set timer let now = Instant::now(); @@ -633,7 +647,7 @@ impl Helper { "XMRig Watchdog | END OF LOOP - Sleeping for [{}]ms...", sleep ); - sleep!(sleep); + tokio::time::sleep(Duration::from_millis(sleep)).await; } else { debug!("XMRig Watchdog | END OF LOOP - Not sleeping!"); } diff --git a/src/helper/xvb/mod.rs b/src/helper/xvb/mod.rs index f41877d..d78072e 100644 --- a/src/helper/xvb/mod.rs +++ b/src/helper/xvb/mod.rs @@ -114,7 +114,8 @@ impl Helper { info!("XvB | spawn watchdog"); thread::spawn(enc!((state_xvb, state_p2pool, state_xmrig) move || { - Self::spawn_xvb_watchdog( + // thread priority, else there are issue on windows but it is also good for other OS + Self::spawn_xvb_watchdog( &gui_api, &pub_api, &process, @@ -218,18 +219,15 @@ impl Helper { info!("XvB Watchdog | Signal has stopped the loop"); break; } - let handle_algo_c = lock!(handle_algo); - let is_algo_started_once = handle_algo_c.is_some(); - let is_algo_finished = handle_algo_c + // let handle_algo_c = lock!(handle_algo); + let is_algo_started_once = lock!(handle_algo).is_some(); + let is_algo_finished = lock!(handle_algo) .as_ref() .is_some_and(|algo| algo.is_finished()); - let handle_request_c = lock!(handle_request); - let is_request_finished = handle_request_c + let is_request_finished = lock!(handle_request) .as_ref() .is_some_and(|request: &JoinHandle<()>| request.is_finished()) - || handle_request_c.is_none(); - drop(handle_algo_c); - drop(handle_request_c); + || lock!(handle_request).is_none(); // Send an HTTP API request only if one minute is passed since the last request or if first loop or if algorithm need to retry or if request is finished and algo is finished or almost finished (only public and private stats). We make sure public and private stats are refreshed before doing another run of the algo. // We make sure algo or request are not rerun when they are not over. // in the case of quick refresh before new run of algo, make sure it doesn't happen multiple times. @@ -353,7 +351,7 @@ impl Helper { if elapsed < 999 { let sleep = (999 - elapsed) as u64; debug!("XvB Watchdog | END OF LOOP - Sleeping for [{}]s...", sleep); - std::thread::sleep(std::time::Duration::from_millis(sleep)) + tokio::time::sleep(Duration::from_millis(sleep)).await; } else { debug!("XMRig Watchdog | END OF LOOP - Not sleeping!"); }