autocommit 2022-01-08 18:38:24 CET
This commit is contained in:
parent
33549184d4
commit
d061a5c313
38 changed files with 179 additions and 371 deletions
|
|
@ -57,6 +57,7 @@ impl<'a, 'b> MsgParser<'a, 'b> {
|
|||
self.int().map(|i| GlobalName::from_raw(i as u32))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn fixed(&mut self) -> Result<Fixed, MsgParserError> {
|
||||
self.int().map(|i| Fixed(i))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,14 +28,6 @@ impl<K: Eq + Hash, V: Clone> CopyHashMap<K, V> {
|
|||
self.map.borrow_mut().get(k).cloned()
|
||||
}
|
||||
|
||||
pub fn get_or_insert_default(&self, k: K) -> V
|
||||
where
|
||||
V: Default,
|
||||
{
|
||||
let mut map = self.map.borrow_mut();
|
||||
map.entry(k).or_insert_with(|| Default::default()).clone()
|
||||
}
|
||||
|
||||
pub fn remove(&self, k: &K) -> Option<V> {
|
||||
self.map.borrow_mut().remove(k)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
use std::cell::{RefCell, RefMut};
|
||||
use std::future::Future;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll, Waker};
|
||||
|
||||
pub struct AsyncLock<T> {
|
||||
data: RefCell<T>,
|
||||
waiters: RefCell<Vec<Waker>>,
|
||||
}
|
||||
|
||||
impl<T> AsyncLock<T> {
|
||||
pub fn lock<'a>(&'a self) -> LockedFuture<'a, T> {
|
||||
LockedFuture { lock: self }
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LockedFuture<'a, T> {
|
||||
lock: &'a AsyncLock<T>,
|
||||
}
|
||||
|
||||
impl<'a, T> Future for LockedFuture<'a, T> {
|
||||
type Output = Locked<'a, T>;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
if let Ok(data) = self.lock.data.try_borrow_mut() {
|
||||
Poll::Ready(Locked {
|
||||
data,
|
||||
lock: self.lock,
|
||||
})
|
||||
} else {
|
||||
self.lock.waiters.borrow_mut().push(cx.waker().clone());
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Locked<'a, T> {
|
||||
data: RefMut<'a, T>,
|
||||
lock: &'a AsyncLock<T>,
|
||||
}
|
||||
|
||||
impl<'a, T> Deref for Locked<'a, T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.data.deref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> DerefMut for Locked<'a, T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.data.deref_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> Drop for Locked<'a, T> {
|
||||
fn drop(&mut self) {
|
||||
for waiter in self.lock.waiters.borrow_mut().drain(..) {
|
||||
waiter.wake();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@ pub mod asyncevent;
|
|||
pub mod buffd;
|
||||
pub mod copyhashmap;
|
||||
pub mod linkedlist;
|
||||
pub mod lock;
|
||||
pub mod numcell;
|
||||
pub mod oneshot;
|
||||
pub mod ptr_ext;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue