#![allow(unused)]
use crate::prelude::fmt;
use parking_lot::{Condvar, Mutex, RwLockReadGuard};
#[derive(Default)]
pub struct RwCondvar {
mutex: Mutex<()>,
condvar: Condvar,
}
impl RwCondvar {
pub const fn new() -> Self {
Self {
mutex: Mutex::new(()),
condvar: Condvar::new(),
}
}
#[inline]
pub fn notify_one(&self) -> bool {
self.condvar.notify_one()
}
#[inline]
pub fn notify_all(&self) -> usize {
self.condvar.notify_all()
}
pub fn wait<T: ?Sized>(&self, rwlock_read_guard: &mut RwLockReadGuard<'_, T>) {
let mutex_guard = self.mutex.lock();
RwLockReadGuard::unlocked(rwlock_read_guard, || {
let mut mutex_guard = mutex_guard;
self.condvar.wait(&mut mutex_guard);
});
}
}
impl fmt::Debug for RwCondvar {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("RwCondvar { .. }")
}
}