Initial documentation

This commit is contained in:
2021-09-24 13:01:58 +03:00
parent 2b5aa03505
commit e85116c5aa
14 changed files with 160 additions and 42 deletions
+9
View File
@@ -1,22 +1,31 @@
//! Synchronization facilities module
use core::ops::{Deref, DerefMut};
use core::cell::UnsafeCell;
/// Dummy lock implementation, does not do any locking.
///
/// Only safe to use before I implement context switching or
/// interrupts are enabled.
#[repr(transparent)]
pub struct NullLock<T: ?Sized> {
value: UnsafeCell<T>
}
/// Dummy lock guard for [NullLock].
#[repr(transparent)]
pub struct NullLockGuard<'a, T: ?Sized> {
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) }
}
/// Returns [NullLockGuard] for this lock
#[inline(always)]
pub fn lock(&self) -> NullLockGuard<T> {
NullLockGuard { value: unsafe { &mut *self.value.get() } }