@@ -101,6 +101,7 @@ impl<T: ?Sized, B: IrqSaveBackend> Lock<T, B> {
/// Before acquiring the lock, it disables interrupts. When the guard is dropped, the interrupt
/// state (either enabled or disabled) is restored to its state before
/// [`lock_irqsave`](Self::lock_irqsave) was called.
+ #[inline(always)]
pub fn lock_irqsave(&self) -> Guard<'_, T, B> {
// SAFETY: The constructor of the type calls `init`, so the existence of the object proves
// that `init` was called.
@@ -210,6 +211,7 @@ impl<T: ?Sized, B: Backend> core::ops::DerefMut for Guard<'_, T, B> {
}
impl<T: ?Sized, B: Backend> Drop for Guard<'_, T, B> {
+ #[inline(always)]
fn drop(&mut self) {
// SAFETY: The caller owns the lock, so it is safe to unlock it.
unsafe { B::unlock(self.lock.state.get(), &self.state) };
@@ -104,12 +104,14 @@ unsafe impl super::Backend for MutexBackend {
unsafe { bindings::__mutex_init(ptr, name, key) }
}
+ #[inline(always)]
unsafe fn lock(ptr: *mut Self::State) -> Self::GuardState {
// SAFETY: The safety requirements of this function ensure that `ptr` points to valid
// memory, and that it has been initialised before.
unsafe { bindings::mutex_lock(ptr) };
}
+ #[inline(always)]
unsafe fn unlock(ptr: *mut Self::State, _guard_state: &Self::GuardState) {
// SAFETY: The safety requirements of this function ensure that `ptr` is valid and that the
// caller is the owner of the mutex.
@@ -122,6 +122,7 @@ unsafe impl super::Backend for SpinLockBackend {
None
}
+ #[inline(always)]
unsafe fn unlock(ptr: *mut Self::State, guard_state: &Self::GuardState) {
match guard_state {
// SAFETY: The safety requirements of this function ensure that `ptr` is valid and that
@@ -141,6 +142,7 @@ unsafe impl super::Backend for SpinLockBackend {
// interrupt state, and the `irqrestore` variant of the lock release functions to restore the state
// in `unlock` -- we use the guard context to determine which method was used to acquire the lock.
unsafe impl super::IrqSaveBackend for SpinLockBackend {
+ #[inline(always)]
unsafe fn lock_irqsave(ptr: *mut Self::State) -> Self::GuardState {
// SAFETY: The safety requirements of this function ensure that `ptr` points to valid
// memory, and that it has been initialised before.
@@ -70,10 +70,12 @@ pub trait ForeignOwnable: Sized {
impl<T: 'static> ForeignOwnable for Box<T> {
type Borrowed<'a> = &'a T;
+ #[inline(always)]
fn into_foreign(self) -> *const core::ffi::c_void {
Box::into_raw(self) as _
}
+ #[inline(always)]
unsafe fn borrow<'a>(ptr: *const core::ffi::c_void) -> &'a T {
// SAFETY: The safety requirements for this function ensure that the object is still alive,
// so it is safe to dereference the raw pointer.
@@ -82,6 +84,7 @@ impl<T: 'static> ForeignOwnable for Box<T> {
unsafe { &*ptr.cast() }
}
+ #[inline(always)]
unsafe fn from_foreign(ptr: *const core::ffi::c_void) -> Self {
// SAFETY: The safety requirements of this function ensure that `ptr` comes from a previous
// call to `Self::into_foreign`.
@@ -92,12 +95,15 @@ impl<T: 'static> ForeignOwnable for Box<T> {
impl ForeignOwnable for () {
type Borrowed<'a> = ();
+ #[inline(always)]
fn into_foreign(self) -> *const core::ffi::c_void {
core::ptr::NonNull::dangling().as_ptr()
}
+ #[inline(always)]
unsafe fn borrow<'a>(_: *const core::ffi::c_void) -> Self::Borrowed<'a> {}
+ #[inline(always)]
unsafe fn from_foreign(_: *const core::ffi::c_void) -> Self {}
}