Format sources
This commit is contained in:
+9
-5
@@ -1,7 +1,7 @@
|
||||
//! Synchronization facilities module
|
||||
|
||||
use core::ops::{Deref, DerefMut};
|
||||
use core::cell::UnsafeCell;
|
||||
use core::ops::{Deref, DerefMut};
|
||||
|
||||
/// Dummy lock implementation, does not do any locking.
|
||||
///
|
||||
@@ -9,26 +9,30 @@ use core::cell::UnsafeCell;
|
||||
/// interrupts are enabled.
|
||||
#[repr(transparent)]
|
||||
pub struct NullLock<T: ?Sized> {
|
||||
value: UnsafeCell<T>
|
||||
value: UnsafeCell<T>,
|
||||
}
|
||||
|
||||
/// Dummy lock guard for [NullLock].
|
||||
#[repr(transparent)]
|
||||
pub struct NullLockGuard<'a, T: ?Sized> {
|
||||
value: &'a mut T
|
||||
value: &'a mut T,
|
||||
}
|
||||
|
||||
impl<T> NullLock<T> {
|
||||
/// Constructs a new instance of the lock, wrapping `value`
|
||||
#[inline(always)]
|
||||
pub const fn new(value: T) -> Self {
|
||||
Self { value: UnsafeCell::new(value) }
|
||||
Self {
|
||||
value: UnsafeCell::new(value),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns [NullLockGuard] for this lock
|
||||
#[inline(always)]
|
||||
pub fn lock(&self) -> NullLockGuard<T> {
|
||||
NullLockGuard { value: unsafe { &mut *self.value.get() } }
|
||||
NullLockGuard {
|
||||
value: unsafe { &mut *self.value.get() },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user