aboutsummaryrefslogtreecommitdiff
path: root/rtic-sync
diff options
context:
space:
mode:
authordatdenkikniet <jcdra1@gmail.com>2025-03-23 10:27:38 +0100
committerEmil Fresk <emil.fresk@gmail.com>2025-03-24 07:36:23 +0000
commitbef2e1b9f007df81e9bd42a94c56699273c0dd82 (patch)
tree4e31bb7bf83278dba72a1195f1f6883985f92cc7 /rtic-sync
parentdae55bd7e40eb8bbf6ead20cc55858485a70d28c (diff)
rtic-sync: remove unnecessary with_mut, safety comment
Diffstat (limited to 'rtic-sync')
-rw-r--r--rtic-sync/src/channel.rs8
-rw-r--r--rtic-sync/src/unsafecell.rs10
2 files changed, 7 insertions, 11 deletions
diff --git a/rtic-sync/src/channel.rs b/rtic-sync/src/channel.rs
index b2792a2..043d058 100644
--- a/rtic-sync/src/channel.rs
+++ b/rtic-sync/src/channel.rs
@@ -57,10 +57,10 @@ macro_rules! cs_access {
where
F: FnOnce(&mut $type) -> R,
{
- self.$name.with_mut(|v| {
- let v = unsafe { &mut *v };
- f(v)
- })
+ let v = self.$name.get_mut();
+ // SAFETY: we have exclusive access due to the critical section.
+ let v = unsafe { v.deref() };
+ f(v)
}
};
}
diff --git a/rtic-sync/src/unsafecell.rs b/rtic-sync/src/unsafecell.rs
index e1774f8..e3730d4 100644
--- a/rtic-sync/src/unsafecell.rs
+++ b/rtic-sync/src/unsafecell.rs
@@ -23,19 +23,15 @@ mod core {
pub fn get_mut(&self) -> MutPtr<T> {
MutPtr(self.0.get())
}
-
- pub unsafe fn with_mut<F, R>(&self, f: F) -> R
- where
- F: FnOnce(*mut T) -> R,
- {
- f(self.0.get())
- }
}
pub struct MutPtr<T>(*mut T);
impl<T> MutPtr<T> {
#[allow(clippy::mut_from_ref)]
+ /// SAFETY: the caller must guarantee that the contained `*mut T` is not
+ /// null, and must uphold the same safety requirements as for
+ /// [`core::primitive::pointer::as_mut`] for the contained `*mut T`.
pub unsafe fn deref(&self) -> &mut T {
&mut *self.0
}