Skip to content

Commit

Permalink
feat(virtio-spec): add WideVolatilePtr::update
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
  • Loading branch information
mkroening committed May 29, 2024
1 parent 5cd998a commit 0a2df9e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions virtio-spec/src/volatile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ impl<'a, A> WideVolatilePtr<'a, le32, A> {
self.low.write(low);
self.high.write(high);
}

/// Updates the contained value using the given closure and volatile instructions.
///
/// See [`VolatilePtr::update`].
pub fn update(self, f: impl FnOnce(le64) -> le64)
where
A: Readable + Writable,
{
let new = f(self.read());
self.write(new);
}
}

impl<'a, A> WideVolatilePtr<'a, be32, A> {
Expand All @@ -85,6 +96,17 @@ impl<'a, A> WideVolatilePtr<'a, be32, A> {
self.low.write(low);
self.high.write(high);
}

/// Updates the contained value using the given closure and volatile instructions.
///
/// See [`VolatilePtr::update`].
pub fn update(self, f: impl FnOnce(be64) -> be64)
where
A: Readable + Writable,
{
let new = f(self.read());
self.write(new);
}
}

macro_rules! impl_wide_field_access {
Expand Down

0 comments on commit 0a2df9e

Please sign in to comment.