pub(crate) mod collect;
mod ref_count;
#[cfg(test)]
mod tests;
use crate::cc::RawCc;
use crate::ref_count::RefCount;
use crate::Trace;
use crate::Tracer;
use collect::ThreadedObjectSpace;
use parking_lot::lock_api::RwLockReadGuard;
use parking_lot::RawRwLock;
use std::marker::PhantomData;
use std::ops::Deref;
pub type ThreadedCc<T> = RawCc<T, ThreadedObjectSpace>;
pub struct ThreadedCcRef<'a, T: ?Sized> {
locked: RwLockReadGuard<'a, RawRwLock, ()>,
parent: &'a ThreadedCc<T>,
_phantom: PhantomData<*mut ()>,
}
unsafe impl<T: Send + Sync> Send for ThreadedCc<T> {}
unsafe impl<T: Send + Sync> Sync for ThreadedCc<T> {}
impl<T: ?Sized> ThreadedCc<T> {
pub fn borrow(&self) -> ThreadedCcRef<'_, T> {
ThreadedCcRef {
locked: self.inner().ref_count.locked().unwrap(),
parent: self,
_phantom: PhantomData,
}
}
}
impl<'a, T: ?Sized> Deref for ThreadedCcRef<'a, T> {
type Target = T;
fn deref(&self) -> &Self::Target {
let _ = &self.locked;
self.parent.inner().deref()
}
}
impl<T: Trace> Trace for ThreadedCc<T> {
fn trace(&self, tracer: &mut Tracer) {
self.inner().trace_t(tracer)
}
#[inline]
fn is_type_tracked() -> bool {
T::is_type_tracked()
}
}
impl Trace for ThreadedCc<dyn Trace> {
fn trace(&self, tracer: &mut Tracer) {
self.inner().trace_t(tracer)
}
#[inline]
fn is_type_tracked() -> bool {
true
}
}
impl Trace for ThreadedCc<dyn Trace + Send> {
fn trace(&self, tracer: &mut Tracer) {
self.inner().trace_t(tracer)
}
#[inline]
fn is_type_tracked() -> bool {
true
}
}
impl Trace for ThreadedCc<dyn Trace + Send + Sync> {
fn trace(&self, tracer: &mut Tracer) {
self.inner().trace_t(tracer)
}
#[inline]
fn is_type_tracked() -> bool {
true
}
}