read_write_store/util/sync/
concurrent_queue.rs1#[cfg(loom)]
2pub struct ConcurrentQueue<Element> {
3 inner: loom::sync::Mutex<Vec<Element>>,
4}
5
6#[cfg(loom)]
7impl<Element> ConcurrentQueue<Element> {
8 pub fn new() -> Self {
9 Self {
10 inner: loom::sync::Mutex::new(Vec::new()),
11 }
12 }
13
14 pub fn push(&self, value: Element) {
15 self.inner.lock().unwrap().insert(0, value)
16 }
17
18 pub fn pop(&self) -> Option<Element> {
19 self.inner.lock().unwrap().pop()
20 }
21}
22
23#[cfg(not(loom))]
24pub struct ConcurrentQueue<Element> {
25 inner: crossbeam_queue::SegQueue<Element>,
26}
27
28#[cfg(not(loom))]
29impl<Element> ConcurrentQueue<Element> {
30 pub fn new() -> Self {
31 Self {
32 inner: crossbeam_queue::SegQueue::new(),
33 }
34 }
35
36 pub fn push(&self, value: Element) {
37 self.inner.push(value)
38 }
39
40 pub fn pop(&self) -> Option<Element> {
41 self.inner.pop()
42 }
43}