turn off time init check after it returns true

this reduces a bit of message chatter for a call that may be
called quite frequently.
This commit is contained in:
bunnie 2022-03-27 17:08:16 +08:00
parent a7912b6296
commit ee695d0181

View file

@ -16,6 +16,7 @@ static TIME_REFCOUNT: AtomicU32 = AtomicU32::new(0);
pub struct LocalTime { pub struct LocalTime {
conn: xous::CID, conn: xous::CID,
warn_count: u32, warn_count: u32,
time_init: bool,
} }
impl LocalTime { impl LocalTime {
pub fn new() -> LocalTime { pub fn new() -> LocalTime {
@ -24,11 +25,13 @@ impl LocalTime {
LocalTime { LocalTime {
conn, conn,
warn_count: 0, warn_count: 0,
time_init: false,
} }
} }
/// Returns the local time as milliseconds since EPOCH, assuming the time zone is set /// Returns the local time as milliseconds since EPOCH, assuming the time zone is set
/// This is provided because we don't have a `libc` to do time zone lookups with `Chrono`. /// This is provided because we don't have a `libc` to do time zone lookups with `Chrono`.
pub fn get_local_time_ms(&mut self) -> Option<u64> { pub fn get_local_time_ms(&mut self) -> Option<u64> {
if !self.time_init {
match xous::send_message(self.conn, match xous::send_message(self.conn,
xous::Message::new_blocking_scalar( xous::Message::new_blocking_scalar(
6, // WallClockTimeInit -- this should not change because it's a libstd mapping 6, // WallClockTimeInit -- this should not change because it's a libstd mapping
@ -49,6 +52,10 @@ impl LocalTime {
return None; return None;
} }
} }
}
// if we got here, time was initialized. Set a flag so we don't check again in the future.
// this reduces the chatter of messages that may routinely happen, e.g. for getting seconds updates on the RTC.
self.time_init = true;
match xous::send_message(self.conn, match xous::send_message(self.conn,
xous::Message::new_blocking_scalar( xous::Message::new_blocking_scalar(
4, 4,