Skip to content

Commit

Permalink
add assert around sleep_heap() discipline in ticktimer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bunnie committed Oct 10, 2023
1 parent bc18c7e commit d457f8b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions services/xous-ticktimer/src/platform/hosted/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit d457f8b

Please sign in to comment.