populated: AtomicUsize,// number of populated items
_lt: PhantomLifetime<'a>,
@ -159,7 +159,42 @@ impl<'a, T> Populator<'a, T>
_lt: PhantomLifetime::new(),
}
}
/// Try to insert `value` at `idx` from an exclusive reference.
///
/// If `idx` already has a value, then `Err(value)` is returned, otherwise, `value` is inserted into the table and a mutable reference to it is returned.
///
/// # Exclusive accesses
/// Since this is an `&mut self` receiver, no atomic operations are required since there are no other threads with a reference to the current populator.
/// If `idx` already has a value, then `Err(value)` is returned, otherwise, `value` is inserted into the table and the number of items now populated is returned.
@ -176,7 +211,10 @@ impl<'a, T> Populator<'a, T>
*ptr=MaybeUninit::new(value);
}
})){
Err(p)=>std::panic::resume_unwind(p),
Err(p)=>{
self.populates[idx].store(false,atomic::Ordering::SeqCst);// Re-set to unoccupied
//TODO: Maybe add inserted bool, or state representing if this Ref has made a change to the populator. The value will be loaded on creation of the Ref, and will be used as a cached version of `completes[idx].load()`
//TODO: OR: Hold a reference to the actual AtomicBool at `idx` itself?
pub(super)inserted: &'reAtomicBool
}
#[derive(Debug, Clone)]// PartialEq, PartialOrd //XXX: TODO: Should this actually be `Clone`? Ref isn't, because its supposed to be a single reference. But since this is arc'd?
/// Checks if the references item currently exists.
#[inline]
pubfnexists(&mutself)-> bool
{
self.pop.exists_exclusive(self.idx)
}
/// Try to insert `value` at the referred slot.
///
/// If the slot already has a value, then `Err(value)` is returned, otherwise, `value` is inserted into the table and a reference to the new element is returned
/// If the slot already has a value, then `Err(value)` is returned, otherwise, `value` is inserted into the table and a mutable reference to the new element is returned.