use super::ReadHandle;
use crate::inner::Inner;
use one_way_slot_map::SlotMapKey as Key;
use std::marker::PhantomData;
use std::mem::ManuallyDrop;
use std::sync::atomic::AtomicPtr;
use std::{fmt, sync};
pub struct ReadHandleFactory<K, P, V>
where
K: Key<P>,
{
pub(super) inner: sync::Arc<AtomicPtr<Inner<ManuallyDrop<V>>>>,
pub(super) epochs: crate::Epochs,
pub(super) _phantom_p: PhantomData<P>,
pub(super) _phantom_k: PhantomData<K>,
}
impl<K, P, V> fmt::Debug for ReadHandleFactory<K, P, V>
where
K: Key<P>,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ReadHandleFactory")
.field("epochs", &self.epochs)
.finish()
}
}
impl<K, P, V> Clone for ReadHandleFactory<K, P, V>
where
K: Key<P>,
{
fn clone(&self) -> Self {
Self {
inner: sync::Arc::clone(&self.inner),
epochs: sync::Arc::clone(&self.epochs),
_phantom_p: Default::default(),
_phantom_k: Default::default(),
}
}
}
impl<K, P, V> ReadHandleFactory<K, P, V>
where
K: Key<P>,
{
pub fn handle(&self) -> ReadHandle<K, P, V> {
ReadHandle::new(
sync::Arc::clone(&self.inner),
sync::Arc::clone(&self.epochs),
)
}
}