From e746ab10da35e5d9ef957c72adf9a3ec7a7df225 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Tue, 23 Aug 2022 22:18:04 -0700 Subject: Queue trait --- src/util/lifo_queue.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/util/lifo_queue.rs') diff --git a/src/util/lifo_queue.rs b/src/util/lifo_queue.rs index 2fa7304..07b0669 100644 --- a/src/util/lifo_queue.rs +++ b/src/util/lifo_queue.rs @@ -1,11 +1,11 @@ //! # Queue //! //! Queue structure -use crate::sync::NullLock; use crate::sync::interface::Mutex; +use crate::sync::NullLock; use crate::util::node::*; use core::fmt; -use core::fmt::{Debug,Formatter}; +use core::fmt::{Debug, Formatter}; /// # Initialize Queue /// - Name: Symbol name @@ -44,14 +44,15 @@ impl<'a, T: Sized, const COUNT: usize> LifoQueue<'a, T, COUNT> { /// # Sharing Thread Safety for LifoQueue unsafe impl Send for LifoQueue<'_, T, COUNT> {} -impl<'a, T: Sized, const COUNT: usize> LifoQueue<'a, T, COUNT> { +impl<'a, T: Sized, const COUNT: usize> crate::util::queue::Queue<'a> for LifoQueue<'a, T, COUNT> { + type Data = T; /// # Initialization of Fixed-Size Pool /// /// Establishes the header and footer of the queue /// as the first and second elements respectively. /// All of the internal elements point to the next /// one and the final element points to `None` - pub fn init(&self) { + fn init(&self) { self.inner.lock(|queue| { for idx in 1..COUNT { if idx != COUNT - 1 { @@ -67,7 +68,7 @@ impl<'a, T: Sized, const COUNT: usize> LifoQueue<'a, T, COUNT> { /// # Pop /// /// Get an item from the queue - pub fn pop(&self) -> Option<&mut Node<'a, T>> { + fn pop(&self) -> Option<&mut Node<'a, T>> { return self.inner.lock(|pool| { if let Some(entry) = pool[0].next { unsafe { @@ -84,7 +85,7 @@ impl<'a, T: Sized, const COUNT: usize> LifoQueue<'a, T, COUNT> { /// # Push /// /// Add the item to the start of the queue. - pub fn push(&self, freed_item: &mut Node<'a, T>) { + fn push(&self, freed_item: &mut Node<'a, T>) { self.inner.lock(|pool| { freed_item.next = pool[0].next; pool[0].next = Some(freed_item as *mut Node<'a, T>); -- cgit v1.2.1