Skip to content

Commit 68d1aa0

Browse files
committed
zephyr: work: Add Drop implementation to futures Work
This will catch instances of the work itself being stopped before the Future running in it has terminated. Not ideal, as it should be permissible to drop it. Signed-off-by: David Brown <[email protected]>
1 parent 08bfb37 commit 68d1aa0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

zephyr/src/work.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,17 @@ pub mod futures {
410410
}
411411
}
412412

413+
impl<F: Future + Send> Drop for Work<F> {
414+
fn drop(&mut self) {
415+
// Ideally, we would actually try to free this, but as a sanity check, make sure the
416+
// strong count of the waker itself is 1, meaning we are the only holder.
417+
let count = Arc::strong_count(&self.waker);
418+
if count != 1 {
419+
panic!("Workwaker has leaked within Work");
420+
}
421+
}
422+
}
423+
413424
/// Waker for a work.
414425
///
415426
/// This is the information needed for the waker to be able to run the thread, as well as

0 commit comments

Comments
 (0)