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 15, 2024
1 parent 3b8c71a commit df8c000
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 df8c000

Please sign in to comment.