summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Cunningham <c@localhost>2022-08-26 18:21:37 -0700
committerChristian Cunningham <c@localhost>2022-08-26 18:21:37 -0700
commitc649f061c72af454199c5a2a9148c4867703da80 (patch)
tree72b61a2e13da78a0874aa0c4b747b10a3e18b77b /src
parent99ab7eadbc72eb0dc2dd776b83373a4b7035f3ea (diff)
Use lock
Diffstat (limited to 'src')
-rw-r--r--src/sync.rs8
-rw-r--r--src/util/fifo_queue.rs9
-rw-r--r--src/util/lifo_queue.rs9
3 files changed, 16 insertions, 10 deletions
diff --git a/src/sync.rs b/src/sync.rs
index 38cffc8..18fc912 100644
--- a/src/sync.rs
+++ b/src/sync.rs
@@ -122,11 +122,11 @@ impl<T> interface::Mutex for SpinLock<T> {
fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut T) -> R) -> R {
loop {
// Loop until acquired the lock
- if let Ok(false) =
- self.lock
- .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
+ match self.lock
+ .compare_exchange(false, true, Ordering::Acquire, Ordering::Relaxed)
{
- break;
+ Ok(_) => { break; }
+ _ => {}
}
}
let data = unsafe { &mut *self.data.get() };
diff --git a/src/util/fifo_queue.rs b/src/util/fifo_queue.rs
index 779bc9d..bb3d8b1 100644
--- a/src/util/fifo_queue.rs
+++ b/src/util/fifo_queue.rs
@@ -2,6 +2,9 @@
//!
//! Provides the FIFO queue structure for allocations
use crate::sync::interface::Mutex;
+#[allow(unused_imports)]
+use crate::sync::SpinLock;
+#[allow(unused_imports)]
use crate::sync::NullLock;
use crate::util::node::*;
use core::fmt;
@@ -20,7 +23,7 @@ macro_rules! init_fifo_queue {
(@gen [$name:tt,$size:tt,$default:tt,$type:ty,$doc:expr]) => {
#[doc = $doc]
#[link_section = ".data.alloc"]
- pub static $name: FifoQueue<'static, $type, {$size+1}> = FifoQueue::new(NullLock::new([Node::new($default); {$size+1}]));
+ pub static $name: FifoQueue<'static, $type, {$size+1}> = FifoQueue::new(SpinLock::new([Node::new($default); {$size+1}]));
};
}
@@ -31,12 +34,12 @@ pub struct FifoQueue<'a, T: Sized, const COUNT: usize> {
/// # Synchronized Pool of items
///
/// Stores synchronization wrapper around the data pool
- pub inner: NullLock<[Node<'a, T>; COUNT]>,
+ pub inner: SpinLock<[Node<'a, T>; COUNT]>,
}
impl<'a, T: Sized, const COUNT: usize> FifoQueue<'a, T, COUNT> {
/// # Create new Fifo Queue
- pub const fn new(initial: NullLock<[Node<'a, T>; COUNT]>) -> Self {
+ pub const fn new(initial: SpinLock<[Node<'a, T>; COUNT]>) -> Self {
Self { inner: initial }
}
}
diff --git a/src/util/lifo_queue.rs b/src/util/lifo_queue.rs
index d63ca6e..cb0648b 100644
--- a/src/util/lifo_queue.rs
+++ b/src/util/lifo_queue.rs
@@ -2,6 +2,9 @@
//!
//! Queue structure
use crate::sync::interface::Mutex;
+#[allow(unused_imports)]
+use crate::sync::SpinLock;
+#[allow(unused_imports)]
use crate::sync::NullLock;
use crate::util::node::*;
use core::fmt;
@@ -20,7 +23,7 @@ macro_rules! init_lifo_queue {
(@gen [$name:tt,$size:tt,$default:tt,$type:ty,$doc:expr]) => {
#[doc = $doc]
#[link_section = ".data.alloc"]
- pub static $name: LifoQueue<'static, $type, {$size+1}> = LifoQueue::new(NullLock::new([Node::new($default); {$size+1}]));
+ pub static $name: LifoQueue<'static, $type, {$size+1}> = LifoQueue::new(SpinLock::new([Node::new($default); {$size+1}]));
};
}
@@ -31,12 +34,12 @@ pub struct LifoQueue<'a, T: Sized, const COUNT: usize> {
/// # Synchronized Pool of items
///
/// Stores synchronization wrapper around the data pool
- pub inner: NullLock<[Node<'a, T>; COUNT]>,
+ pub inner: SpinLock<[Node<'a, T>; COUNT]>,
}
impl<'a, T: Sized, const COUNT: usize> LifoQueue<'a, T, COUNT> {
/// # Create new Lifo Queue
- pub const fn new(initial: NullLock<[Node<'a, T>; COUNT]>) -> Self {
+ pub const fn new(initial: SpinLock<[Node<'a, T>; COUNT]>) -> Self {
Self { inner: initial }
}
}