Skip to content

Commit

Permalink
Change new_locked -> new.
Browse files Browse the repository at this point in the history
  • Loading branch information
travis1829 committed Mar 31, 2021
1 parent 2151601 commit 6b8c9eb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
42 changes: 21 additions & 21 deletions kernel-rs/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,21 @@ pub struct Rc<A: Arena> {
unsafe impl<T: Sync, A: Arena<Data = T>> Send for Rc<A> {}

impl<T, const CAPACITY: usize> ArrayArena<T, CAPACITY> {
/// Returns an `ArrayArena` of size `CAPACITY` that is wrapped by a `Spinlock`
/// and filled with `D`'s const default value. Note that `D` must `impl const [Default]`.
/// Returns an `ArrayArena` of size `CAPACITY` that is filled with `D`'s const default value.
/// Note that `D` must `impl const Default`.
///
/// # Examples
///
/// ```rust,no_run
/// let arr_arena = ArrayArena::<D, 100>::new_locked("arr_arena");
/// let arr_arena = ArrayArena::<D, 100>::new();
/// ```
pub const fn new_locked<D: Default>(name: &'static str) -> Spinlock<ArrayArena<D, CAPACITY>> {
Spinlock::new(
name,
ArrayArena {
entries: array![_ => RcCell::new(Default::default()); CAPACITY],
},
)
// Note: We cannot use the generic `T` in the following function, since we need to only allow
// types that `impl const Default`, not just `impl Default`.
#[allow(clippy::new_ret_no_self)]
pub const fn new<D: Default>() -> ArrayArena<D, CAPACITY> {
ArrayArena {
entries: array![_ => RcCell::new(Default::default()); CAPACITY],
}
}
}

Expand Down Expand Up @@ -259,22 +259,22 @@ unsafe impl<T> ListNode for MruEntry<T> {
}

impl<T, const CAPACITY: usize> MruArena<T, CAPACITY> {
/// Returns an `MruArena` of size `CAPACITY` that is wrapped by a `Spinlock`
/// and filled with `D`'s const default value. Note that `D` must `impl const [Default]`.
/// Returns an `MruArena` of size `CAPACITY` that is filled with `D`'s const default value.
/// Note that `D` must `impl const Default`.
///
/// # Examples
///
/// ```rust,no_run
/// let mru_arena = MruArena::<D, 100>::new_locked("mru_arena");
/// let mru_arena = MruArena::<D, 100>::new();
/// ```
pub const fn new_locked<D: Default>(name: &'static str) -> Spinlock<MruArena<D, CAPACITY>> {
Spinlock::new(
name,
MruArena {
entries: array![_ => MruEntry::new(Default::default()); CAPACITY],
list: unsafe { List::new() },
},
)
// Note: We cannot use the generic `T` in the following function, since we need to only allow
// types that `impl const Default`, not just `impl Default`.
#[allow(clippy::new_ret_no_self)]
pub const fn new<D: Default>() -> MruArena<D, CAPACITY> {
MruArena {
entries: array![_ => MruEntry::new(Default::default()); CAPACITY],
list: unsafe { List::new() },
}
}

pub fn init(self: Pin<&mut Self>) {
Expand Down
4 changes: 2 additions & 2 deletions kernel-rs/src/bio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl BufEntry {
}
}

#[rustfmt::skip] // Need this to use #![feature(const_trait_impl)]
#[rustfmt::skip] // Need this if lower than rustfmt 1.4.34
impl const Default for BufEntry {
fn default() -> Self {
Self::zero()
Expand Down Expand Up @@ -154,7 +154,7 @@ impl Bcache {
///
/// The caller should make sure that `Bcache` never gets moved.
pub const unsafe fn zero() -> Self {
MruArena::<BufEntry, NBUF>::new_locked("BCACHE")
Spinlock::new("BCACHE", MruArena::<BufEntry, NBUF>::new())
}

/// Return a unlocked buf with the contents of the indicated block.
Expand Down
4 changes: 2 additions & 2 deletions kernel-rs/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl File {
}
}

#[rustfmt::skip] // Need this to use #![feature(const_trait_impl)]
#[rustfmt::skip] // Need this if lower than rustfmt 1.4.34
impl const Default for File {
fn default() -> Self {
Self::zero()
Expand Down Expand Up @@ -239,7 +239,7 @@ impl ArenaObject for File {

impl FileTable {
pub const fn zero() -> Self {
ArrayArena::<File, NFILE>::new_locked("FTABLE")
Spinlock::new("FTABLE", ArrayArena::<File, NFILE>::new())
}

/// Allocate a file structure.
Expand Down
4 changes: 2 additions & 2 deletions kernel-rs/src/fs/inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ impl InodeGuard<'_> {
}
}

#[rustfmt::skip] // Need this to use #![feature(const_trait_impl)]
#[rustfmt::skip] // Need this if lower than rustfmt 1.4.34
impl const Default for Inode {
fn default() -> Self {
Self::zero()
Expand Down Expand Up @@ -815,7 +815,7 @@ impl Inode {

impl Itable {
pub const fn zero() -> Self {
ArrayArena::<Inode, NINODE>::new_locked("ITABLE")
Spinlock::new("ITABLE", ArrayArena::<Inode, NINODE>::new())
}

/// Find the inode with number inum on device dev
Expand Down

0 comments on commit 6b8c9eb

Please sign in to comment.