Skip to content

Commit

Permalink
Allow Cache to return a single block
Browse files Browse the repository at this point in the history
In some cases it is valuable for the block cache to be used without `spin`.
We expose `next_block` to return a `Block` reference as soon as one is
available, blocking the callers meanwhile.

Signed-off-by: Brian L. Troutwine <[email protected]>
  • Loading branch information
blt committed Oct 24, 2024
1 parent 52be4e2 commit 48c2b8e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lading_payload/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,23 @@ impl Cache {
},
}
}

/// Return a `Block` from the `Cache`
///
/// This is a blocking function that returns a single `Block` instance as
/// soon as one is ready, blocking the caller until one is available.
pub fn next_block(&mut self) -> &Block {
match self {
Self::Fixed {
ref mut idx,
blocks,
} => {
let block = &blocks[*idx];
*idx = (*idx + 1) % blocks.len();
block
}
}
}
}

/// Construct a new block cache of form defined by `serializer`.
Expand Down

0 comments on commit 48c2b8e

Please sign in to comment.