fix: remove arc mutex overhead and update gui ticks

This commit is contained in:
mostafaei2002 2024-07-21 16:46:23 +03:30
parent 1617882f29
commit 783b3148c7

View file

@ -491,15 +491,15 @@ impl Helper {
// 4. Loop as watchdog
let mut first_loop = true;
let mut last_p2pool_request = Arc::new(Mutex::new(tokio::time::Instant::now()));
let mut last_status_request = Arc::new(Mutex::new(tokio::time::Instant::now()));
let mut last_p2pool_request = tokio::time::Instant::now();
let mut last_status_request = tokio::time::Instant::now();
info!("P2Pool | Entering watchdog mode... woof!");
loop {
// Set timer
let now = Instant::now();
debug!("P2Pool Watchdog | ----------- Start of loop -----------");
lock!(gui_api).tick = (lock!(last_p2pool_request).elapsed().as_secs() % 60) as u8;
lock!(gui_api).tick = (last_p2pool_request.elapsed().as_secs() % 60) as u8;
// Check if the process is secretly died without us knowing :)
if check_died(
@ -544,7 +544,7 @@ impl Helper {
}
// If more than 1 minute has passed, read the other API files.
let last_p2pool_request_expired =
lock!(last_p2pool_request).elapsed() >= Duration::from_secs(60);
last_p2pool_request.elapsed() >= Duration::from_secs(60);
if last_p2pool_request_expired {
debug!("P2Pool Watchdog | Attempting [network] & [pool] API file read");
@ -557,13 +557,13 @@ impl Helper {
PrivP2poolPoolApi::from_str(&pool_api),
) {
PubP2poolApi::update_from_network_pool(&pub_api, network_api, pool_api);
last_p2pool_request = Arc::new(Mutex::new(tokio::time::Instant::now()));
last_p2pool_request = tokio::time::Instant::now();
}
}
}
let last_status_request_expired =
lock!(last_status_request).elapsed() >= Duration::from_secs(60);
last_status_request.elapsed() >= Duration::from_secs(60);
if (last_status_request_expired || first_loop)
&& lock!(process).state == ProcessState::Alive
@ -581,7 +581,7 @@ impl Helper {
if let Err(e) = stdin.flush() {
error!("P2Pool Watchdog | STDIN flush error: {}", e);
}
last_status_request = Arc::new(Mutex::new(tokio::time::Instant::now()));
last_status_request = tokio::time::Instant::now();
}
// Sleep (only if 900ms hasn't passed)
@ -997,66 +997,66 @@ impl PubP2poolApi {
// let blanks = " ".repeat(60 - (self.tick - 1));
// [use crate::PubP2poolApi;use crate::PubP2poolApi;"[", &stars, &blanks, "]"].concat().as_str()
match self.tick {
1 => "[ ]",
2 => "[* ]",
3 => "[** ]",
4 => "[*** ]",
5 => "[**** ]",
6 => "[***** ]",
7 => "[****** ]",
8 => "[******* ]",
9 => "[******** ]",
10 => "[********* ]",
11 => "[********** ]",
12 => "[*********** ]",
13 => "[************ ]",
14 => "[************* ]",
15 => "[************** ]",
16 => "[*************** ]",
17 => "[**************** ]",
18 => "[***************** ]",
19 => "[****************** ]",
20 => "[******************* ]",
21 => "[******************** ]",
22 => "[********************* ]",
23 => "[********************** ]",
24 => "[*********************** ]",
25 => "[************************ ]",
26 => "[************************* ]",
27 => "[************************** ]",
28 => "[*************************** ]",
29 => "[**************************** ]",
30 => "[***************************** ]",
31 => "[****************************** ]",
32 => "[******************************* ]",
33 => "[******************************** ]",
34 => "[********************************* ]",
35 => "[********************************** ]",
36 => "[*********************************** ]",
37 => "[************************************ ]",
38 => "[************************************* ]",
39 => "[************************************** ]",
40 => "[*************************************** ]",
41 => "[**************************************** ]",
42 => "[***************************************** ]",
43 => "[****************************************** ]",
44 => "[******************************************* ]",
45 => "[******************************************** ]",
46 => "[********************************************* ]",
47 => "[********************************************** ]",
48 => "[*********************************************** ]",
49 => "[************************************************ ]",
50 => "[************************************************* ]",
51 => "[************************************************** ]",
52 => "[*************************************************** ]",
53 => "[**************************************************** ]",
54 => "[***************************************************** ]",
55 => "[****************************************************** ]",
56 => "[******************************************************* ]",
57 => "[******************************************************** ]",
58 => "[********************************************************* ]",
59 => "[********************************************************** ]",
60 => "[*********************************************************** ]",
0 => "[ ]",
1 => "[* ]",
2 => "[** ]",
3 => "[*** ]",
4 => "[**** ]",
5 => "[***** ]",
6 => "[****** ]",
7 => "[******* ]",
8 => "[******** ]",
9 => "[********* ]",
10 => "[********** ]",
11 => "[*********** ]",
12 => "[************ ]",
13 => "[************* ]",
14 => "[************** ]",
15 => "[*************** ]",
16 => "[**************** ]",
17 => "[***************** ]",
18 => "[****************** ]",
19 => "[******************* ]",
20 => "[******************** ]",
21 => "[********************* ]",
22 => "[********************** ]",
23 => "[*********************** ]",
24 => "[************************ ]",
25 => "[************************* ]",
26 => "[************************** ]",
27 => "[*************************** ]",
28 => "[**************************** ]",
29 => "[***************************** ]",
30 => "[****************************** ]",
31 => "[******************************* ]",
32 => "[******************************** ]",
33 => "[********************************* ]",
34 => "[********************************** ]",
35 => "[*********************************** ]",
36 => "[************************************ ]",
37 => "[************************************* ]",
38 => "[************************************** ]",
39 => "[*************************************** ]",
40 => "[**************************************** ]",
41 => "[***************************************** ]",
42 => "[****************************************** ]",
43 => "[******************************************* ]",
44 => "[******************************************** ]",
45 => "[********************************************* ]",
46 => "[********************************************** ]",
47 => "[*********************************************** ]",
48 => "[************************************************ ]",
49 => "[************************************************* ]",
50 => "[************************************************** ]",
51 => "[*************************************************** ]",
52 => "[**************************************************** ]",
53 => "[***************************************************** ]",
54 => "[****************************************************** ]",
55 => "[******************************************************* ]",
56 => "[******************************************************** ]",
57 => "[********************************************************* ]",
58 => "[********************************************************** ]",
59 => "[*********************************************************** ]",
_ => "[************************************************************]",
}
}