autocommit 2022-03-09 17:51:17 CET
This commit is contained in:
parent
4df6b559b7
commit
0399772467
35 changed files with 429 additions and 423 deletions
29
src/utils/syncqueue.rs
Normal file
29
src/utils/syncqueue.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use std::cell::UnsafeCell;
|
||||
use std::collections::VecDeque;
|
||||
use crate::utils::ptr_ext::MutPtrExt;
|
||||
|
||||
pub struct SyncQueue<T> {
|
||||
el: UnsafeCell<VecDeque<T>>,
|
||||
}
|
||||
|
||||
impl<T> Default for SyncQueue<T> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
el: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> SyncQueue<T> {
|
||||
pub fn push(&self, t: T) {
|
||||
unsafe {
|
||||
self.el.get().deref_mut().push_back(t);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pop(&self) -> Option<T> {
|
||||
unsafe {
|
||||
self.el.get().deref_mut().pop_front()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue