Skip to content

Commit 46af251

Browse files
committed
zephyr: work: futures: size_of utility function
Provode a `size_of` utility that can take a Future and return how much memory is needed to schedule it. Signed-off-by: David Brown <[email protected]>
1 parent 60a64fe commit 46af251

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

zephyr/src/work/futures.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ impl WorkBuilder {
174174
}
175175
}
176176

177+
/// Calculate the memory needed by scheduled work. This does not include the size of the Answer
178+
/// (which can be dropped).
179+
pub fn work_size<F: Future>(f: F) -> usize {
180+
WorkData::size_of(f)
181+
}
182+
177183
/// A potentially running Work.
178184
///
179185
/// This encapsulates a Future that is potentially running in the Zephyr work queue system.
@@ -535,6 +541,13 @@ impl<F: Future> WorkData<F> {
535541
let this = Box::from_raw(ptr);
536542
Pin::new_unchecked(this)
537543
}
544+
545+
/// Determine the size of WorkData for a given Future.
546+
///
547+
/// It is difficult to otherwise calculate this. The future will be dropped by this.
548+
pub fn size_of(_: F) -> usize {
549+
mem::size_of::<Self>()
550+
}
538551
}
539552

540553
/// A VoidWaker is used when we don't use the Waker mechanism. There is no data associated with

0 commit comments

Comments
 (0)