mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-29 06:54:33 +01:00
add a get method to get a raw pointer to the resource data
This commit is contained in:
parent
0ef71d29a8
commit
f3b73bcc12
1 changed files with 30 additions and 20 deletions
50
src/lib.rs
50
src/lib.rs
|
@ -119,6 +119,11 @@ where
|
|||
unsafe { &mut *self.peripheral.get() }
|
||||
}
|
||||
|
||||
/// Returns a mutable pointer to the wrapped value
|
||||
pub fn get(&self) -> *mut P {
|
||||
self.peripheral.get()
|
||||
}
|
||||
|
||||
/// Locks the resource, preventing tasks with priority lower than `Ceiling`
|
||||
/// from preempting the current task
|
||||
pub fn lock<R, F, Ctxt>(&'static self, _ctxt: &Ctxt, f: F) -> R
|
||||
|
@ -204,26 +209,6 @@ impl<T, C> Resource<T, C>
|
|||
where
|
||||
C: Ceiling,
|
||||
{
|
||||
/// Locks the resource, preventing tasks with priority lower than `Ceiling`
|
||||
/// from preempting the current task
|
||||
pub fn lock<F, R, Ctxt>(&'static self, _ctxt: &Ctxt, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&T, C) -> R,
|
||||
Ctxt: Context,
|
||||
{
|
||||
unsafe { lock(f, self.data.get(), C::ceiling()) }
|
||||
}
|
||||
|
||||
/// Mutably locks the resource, preventing tasks with priority lower than
|
||||
/// `Ceiling` from preempting the current task
|
||||
pub fn lock_mut<F, R, Ctxt>(&'static self, _ctxt: &mut Ctxt, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&mut T, C) -> R,
|
||||
Ctxt: Context,
|
||||
{
|
||||
unsafe { lock_mut(f, self.data.get(), C::ceiling()) }
|
||||
}
|
||||
|
||||
/// Borrows the resource without locking
|
||||
///
|
||||
/// NOTE The system ceiling must be higher than this resource ceiling
|
||||
|
@ -243,6 +228,31 @@ where
|
|||
{
|
||||
unsafe { &mut *self.data.get() }
|
||||
}
|
||||
|
||||
/// Returns a mutable pointer to the wrapped value
|
||||
pub fn get(&self) -> *mut T {
|
||||
self.data.get()
|
||||
}
|
||||
|
||||
/// Locks the resource, preventing tasks with priority lower than `Ceiling`
|
||||
/// from preempting the current task
|
||||
pub fn lock<F, R, Ctxt>(&'static self, _ctxt: &Ctxt, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&T, C) -> R,
|
||||
Ctxt: Context,
|
||||
{
|
||||
unsafe { lock(f, self.data.get(), C::ceiling()) }
|
||||
}
|
||||
|
||||
/// Mutably locks the resource, preventing tasks with priority lower than
|
||||
/// `Ceiling` from preempting the current task
|
||||
pub fn lock_mut<F, R, Ctxt>(&'static self, _ctxt: &mut Ctxt, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&mut T, C) -> R,
|
||||
Ctxt: Context,
|
||||
{
|
||||
unsafe { lock_mut(f, self.data.get(), C::ceiling()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Resource<T, C0> {
|
||||
|
|
Loading…
Reference in a new issue