From b161b021fe30292020f11182e0cadcbaffa1d2dd Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 11 Jan 2022 16:19:31 +0800 Subject: [PATCH] stop pump updates while we're doing the RTC setting The RTC set dialog box is blocking, the pump will eventually lock up the system if we don't stop it. nb: ~200k saved in RAM with the refactor --- services/llio/src/main.rs | 4 ++-- services/status/src/main.rs | 30 +++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index 318f4f860..af7ad568c 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -698,10 +698,10 @@ fn xmain() -> ! { // create the I2C handler thread // - codec - // - rtc xx -> this is now handed off directly in the spawn of the sub command + // - rtc // - shellchat // I2C can be used to set time, which can have security implications; we are more strict on counting who can have access to this resource. - let i2c_sid = xns.register_name(api::SERVER_NAME_I2C, Some(2)).expect("can't register I2C thread"); + let i2c_sid = xns.register_name(api::SERVER_NAME_I2C, Some(3)).expect("can't register I2C thread"); log::trace!("registered I2C thread with NS -- {:?}", i2c_sid); let _ = thread::spawn({ let i2c_sid = i2c_sid.clone(); diff --git a/services/status/src/main.rs b/services/status/src/main.rs index b742511f3..f5fecf935 100644 --- a/services/status/src/main.rs +++ b/services/status/src/main.rs @@ -20,6 +20,8 @@ use llio::Weekday; use std::collections::HashMap; use std::sync::{Arc, Mutex}; +use std::sync::atomic::{AtomicBool, Ordering}; + #[cfg_attr( not(any(target_os = "none", target_os = "xous")), allow(unused_imports) @@ -71,16 +73,18 @@ pub fn dt_callback(dt: llio::DateTime) { } } -pub fn pump_thread(conn: usize) { +pub fn pump_thread(conn: usize, pump_run: Arc) { let ticktimer = ticktimer_server::Ticktimer::new().unwrap(); loop { - match send_message( - conn as u32, - Message::new_scalar(StatusOpcode::Pump.to_usize().unwrap(), 0, 0, 0, 0), - ) { - Err(xous::Error::ServerNotFound) => break, - Ok(xous::Result::Ok) => {} - _ => panic!("unhandled error in status pump thread"), + if pump_run.load(Ordering::Relaxed) { + match send_message( + conn as u32, + Message::new_scalar(StatusOpcode::Pump.to_usize().unwrap(), 0, 0, 0, 0), + ) { + Err(xous::Error::ServerNotFound) => break, + Ok(xous::Result::Ok) => {} + _ => panic!("unhandled error in status pump thread"), + } } ticktimer.sleep_ms(1000).unwrap(); } @@ -125,8 +129,14 @@ fn xmain() -> ! { .expect("|status: can't register server"); // create a connection for callback hooks unsafe { CB_TO_MAIN_CONN = Some(xous::connect(status_sid).unwrap()) }; + let pump_run = Arc::new(AtomicBool::new(true)); let pump_conn = xous::connect(status_sid).unwrap(); - xous::create_thread_1(pump_thread, pump_conn as _).expect("couldn't create pump thread"); + let _ = thread::spawn({ + let pump_run = pump_run.clone(); + move || { + pump_thread(pump_conn as _, pump_run); + } + }); let gam = gam::Gam::new(&xns).expect("|status: can't connect to GAM"); let ticktimer = ticktimer_server::Ticktimer::new().expect("Couldn't connect to Ticktimer"); @@ -501,6 +511,7 @@ fn xmain() -> ! { datetime = Some(dt); } Some(StatusOpcode::UxSetTime) => msg_scalar_unpack!(msg, _, _, _, _, { + pump_run.store(false, Ordering::Relaxed); // stop status updates while we do this let secs: u8; let mins: u8; let hours: u8; @@ -584,6 +595,7 @@ fn xmain() -> ! { weekday }; rtc.set_rtc(dt).expect("couldn't set the current time"); + pump_run.store(true, Ordering::Relaxed); // stop status updates while we do this }), Some(StatusOpcode::Quit) => { break;