#![deny(clippy::undocumented_unsafe_blocks)]
extern crate alloc;
pub mod epoch_counters;
use alloc::sync::Arc;
use epoch_counters::EpochCounterPool;
use crate::epoch_counters::EpochCounter;
pub mod atomic;
pub mod rwlock;
pub mod rcu_ref;
pub trait Rcu {
type Item;
type Pool: EpochCounterPool;
fn new(initial: impl Into<Arc<Self::Item>>, epoch_counter_pool: Self::Pool) -> Self;
#[cfg(feature = "thread_local_counter")]
fn read(&self) -> rcu_ref::RcuRef<Self::Item, Self::Item>
where
Self: Rcu<Pool = epoch_counters::GlobalEpochCounterPool>,
{
let arc = crate::epoch_counters::with_thread_local_epoch_counter(|epoch_counter| {
unsafe { self.raw_read(epoch_counter) }
});
rcu_ref::RcuRef::<Self::Item, Self::Item>::new(arc)
}
fn replace(&self, new_value: impl Into<Arc<Self::Item>>) -> Arc<Self::Item>;
#[cfg(feature = "thread_local_counter")]
fn try_update<F, R>(&self, mut update: F) -> Option<Arc<Self::Item>>
where
Self: Rcu<Pool = epoch_counters::GlobalEpochCounterPool>,
F: FnMut(&Self::Item) -> Option<R>,
R: Into<Arc<Self::Item>>,
{
crate::epoch_counters::with_thread_local_epoch_counter(|epoch_counter| unsafe {
self.raw_try_update(move |old| update(old).map(Into::into), epoch_counter)
})
}
unsafe fn raw_read(&self, epoch_counter: &EpochCounter) -> Arc<Self::Item>;
unsafe fn raw_try_update(
&self,
update: impl FnMut(&Self::Item) -> Option<Arc<Self::Item>>,
epoch_counter: &EpochCounter,
) -> Option<Arc<Self::Item>>;
}