Skip to content

Commit c9204cb

Browse files
committed
rtic-sync: remove unnecessary with_mut, safety comment
1 parent 25b6002 commit c9204cb

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

rtic-sync/src/channel.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ macro_rules! cs_access {
5757
where
5858
F: FnOnce(&mut $type) -> R,
5959
{
60-
self.$name.with_mut(|v| {
61-
let v = unsafe { &mut *v };
62-
f(v)
63-
})
60+
let v = self.$name.get_mut();
61+
// SAFETY: we have exclusive access due to the critical section.
62+
let v = unsafe { v.deref() };
63+
f(v)
6464
}
6565
};
6666
}

rtic-sync/src/unsafecell.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,15 @@ mod core {
2323
pub fn get_mut(&self) -> MutPtr<T> {
2424
MutPtr(self.0.get())
2525
}
26-
27-
pub unsafe fn with_mut<F, R>(&self, f: F) -> R
28-
where
29-
F: FnOnce(*mut T) -> R,
30-
{
31-
f(self.0.get())
32-
}
3326
}
3427

3528
pub struct MutPtr<T>(*mut T);
3629

3730
impl<T> MutPtr<T> {
3831
#[allow(clippy::mut_from_ref)]
32+
/// SAFETY: the caller must guarantee that the contained `*mut T` is not
33+
/// null, and must uphold the same safety requirements as for
34+
/// [`core::primitive::pointer::as_mut`] for the contained `*mut T`.
3935
pub unsafe fn deref(&self) -> &mut T {
4036
&mut *self.0
4137
}

0 commit comments

Comments
 (0)