#![deny(missing_docs)]
#![no_std]
#![doc(html_root_url="https://docs.rs/bare-metal/1.0")]
use core::cell::UnsafeCell;
use core::marker::PhantomData;
#[derive(Clone, Copy, Debug)]
pub struct CriticalSection<'cs> {
_0: PhantomData<&'cs ()>,
}
impl<'cs> CriticalSection<'cs> {
#[inline(always)]
pub unsafe fn new() -> Self {
CriticalSection { _0: PhantomData }
}
}
#[derive(Debug)]
pub struct Mutex<T> {
inner: UnsafeCell<T>,
}
impl<T> Mutex<T> {
pub const fn new(value: T) -> Self {
Mutex {
inner: UnsafeCell::new(value),
}
}
pub fn get_mut(&mut self) -> &mut T {
unsafe { &mut *self.inner.get() }
}
pub fn into_inner(self) -> T {
self.inner.into_inner()
}
pub fn borrow<'cs>(&'cs self, _cs: CriticalSection<'cs>) -> &'cs T {
unsafe { &*self.inner.get() }
}
}
unsafe impl<T> Sync for Mutex<T> where T: Send {}
#[allow(dead_code)]
#[doc(hidden)]
const GH_6: () = ();