From d457f8b555bd05d168851f4a6ce8b8616e82af73 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 10 Oct 2023 22:22:30 +0800 Subject: [PATCH] add assert around sleep_heap() discipline in ticktimer Every entry into the sleep_heap() should be unique. Any insert() call that returns a value means we're going to drop a wake-up event. Add an assert()! that will trigger a panic if this invariant is not met. --- .../xous-ticktimer/src/platform/cramium/implementation.rs | 4 ++-- services/xous-ticktimer/src/platform/hosted/implementation.rs | 4 ++-- .../xous-ticktimer/src/platform/precursor/implementation.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/services/xous-ticktimer/src/platform/cramium/implementation.rs b/services/xous-ticktimer/src/platform/cramium/implementation.rs index 8d4e45bfc..dfe101798 100644 --- a/services/xous-ticktimer/src/platform/cramium/implementation.rs +++ b/services/xous-ticktimer/src/platform/cramium/implementation.rs @@ -306,7 +306,7 @@ impl XousTickTimer { if let Some(current) = self.stop_interrupt() { #[cfg(feature = "debug-print")] log::info!("Existing request was {:?}", current); - sleep_heap.insert(current.msec, current); + assert!(sleep_heap.insert(current.msec, current).is_none(), "Existing sleep_heap entry would be overwritten"); } else { #[cfg(feature = "debug-print")] log::info!("There was no existing sleep() request"); @@ -363,7 +363,7 @@ impl XousTickTimer { #[cfg(feature = "debug-print")] log::info!("Modified, the request was: {:?}", request); - sleep_heap.insert(request.msec, request); + assert!(sleep_heap.insert(request.msec, request).is_none(), "Existing sleep_heap entry would be overwritten"); } else { #[cfg(feature = "debug-print")] log::info!("No new sleep request"); diff --git a/services/xous-ticktimer/src/platform/hosted/implementation.rs b/services/xous-ticktimer/src/platform/hosted/implementation.rs index 2e04702c9..9da84ec0e 100644 --- a/services/xous-ticktimer/src/platform/hosted/implementation.rs +++ b/services/xous-ticktimer/src/platform/hosted/implementation.rs @@ -174,7 +174,7 @@ impl XousTickTimer { if let Some(current) = self.stop_interrupt() { #[cfg(feature = "debug-print")] log::info!("Existing request was {:?}", current); - sleep_heap.insert(current.msec, current); + assert!(sleep_heap.insert(current.msec, current).is_none(), "Existing sleep_heap entry would be overwritten"); } else { #[cfg(feature = "debug-print")] log::info!("There was no existing sleep() request"); @@ -231,7 +231,7 @@ impl XousTickTimer { #[cfg(feature = "debug-print")] log::info!("Modified, the request was: {:?}", request); - sleep_heap.insert(request.msec, request); + assert!(sleep_heap.insert(request.msec, request).is_none(), "Existing sleep_heap entry would be overwritten"); } else { #[cfg(feature = "debug-print")] log::info!("No new sleep request"); diff --git a/services/xous-ticktimer/src/platform/precursor/implementation.rs b/services/xous-ticktimer/src/platform/precursor/implementation.rs index 380b8ffe7..3c259a6e5 100644 --- a/services/xous-ticktimer/src/platform/precursor/implementation.rs +++ b/services/xous-ticktimer/src/platform/precursor/implementation.rs @@ -287,7 +287,7 @@ impl XousTickTimer { if let Some(current) = self.stop_interrupt() { #[cfg(feature = "debug-print")] log::info!("Existing request was {:?}", current); - sleep_heap.insert(current.msec, current); + assert!(sleep_heap.insert(current.msec, current).is_none(), "Existing sleep_heap entry would be overwritten"); } else { #[cfg(feature = "debug-print")] log::info!("There was no existing sleep() request"); @@ -344,7 +344,7 @@ impl XousTickTimer { #[cfg(feature = "debug-print")] log::info!("Modified, the request was: {:?}", request); - sleep_heap.insert(request.msec, request); + assert!(sleep_heap.insert(request.msec, request).is_none(), "Existing sleep_heap entry would be overwritten"); } else { #[cfg(feature = "debug-print")] log::info!("No new sleep request");