mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-18 05:45:19 +01:00
rtic-sync: remove unnecessary with_mut, safety comment
This commit is contained in:
parent
dae55bd7e4
commit
bef2e1b9f0
2 changed files with 7 additions and 11 deletions
|
|
@ -57,10 +57,10 @@ macro_rules! cs_access {
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut $type) -> R,
|
F: FnOnce(&mut $type) -> R,
|
||||||
{
|
{
|
||||||
self.$name.with_mut(|v| {
|
let v = self.$name.get_mut();
|
||||||
let v = unsafe { &mut *v };
|
// SAFETY: we have exclusive access due to the critical section.
|
||||||
f(v)
|
let v = unsafe { v.deref() };
|
||||||
})
|
f(v)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,19 +23,15 @@ mod core {
|
||||||
pub fn get_mut(&self) -> MutPtr<T> {
|
pub fn get_mut(&self) -> MutPtr<T> {
|
||||||
MutPtr(self.0.get())
|
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);
|
pub struct MutPtr<T>(*mut T);
|
||||||
|
|
||||||
impl<T> MutPtr<T> {
|
impl<T> MutPtr<T> {
|
||||||
#[allow(clippy::mut_from_ref)]
|
#[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 {
|
pub unsafe fn deref(&self) -> &mut T {
|
||||||
&mut *self.0
|
&mut *self.0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue