mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 09:53:24 +00:00
Remove Cell
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
39ea6a417c
commit
3e9c4a8d45
@ -1,39 +0,0 @@
|
|||||||
use core::{
|
|
||||||
cell::UnsafeCell,
|
|
||||||
ops::{Deref, DerefMut},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
#[repr(transparent)]
|
|
||||||
pub struct Cell<T>(UnsafeCell<T>);
|
|
||||||
|
|
||||||
unsafe impl<T> Sync for Cell<T> {}
|
|
||||||
|
|
||||||
impl<T> Cell<T> {
|
|
||||||
/// User is responsible to guarantee that inner struct is only used in
|
|
||||||
/// uniprocessor.
|
|
||||||
#[inline(always)]
|
|
||||||
pub const fn new(val: T) -> Self {
|
|
||||||
Self(UnsafeCell::new(val))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn get(&self) -> &mut T {
|
|
||||||
unsafe { &mut *self.0.get() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Deref for Cell<T> {
|
|
||||||
type Target = T;
|
|
||||||
#[inline(always)]
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
self.get()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> DerefMut for Cell<T> {
|
|
||||||
#[inline(always)]
|
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
||||||
self.get()
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,7 +16,6 @@
|
|||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
mod boot;
|
mod boot;
|
||||||
pub(crate) mod cell;
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod cpu;
|
pub mod cpu;
|
||||||
pub mod device;
|
pub mod device;
|
||||||
|
Reference in New Issue
Block a user