Trait arc_swap::gen_lock::LockStorage
source · pub unsafe trait LockStorage: Default {
type Shards: AsRef<[Shard]>;
fn gen_idx(&self) -> &AtomicUsize;
fn shards(&self) -> &Self::Shards;
fn choose_shard(&self) -> usize;
}
Expand description
Abstraction of the place where generation locks are stored.
The trait is unsafe because if the trait messes up with the values stored in there in any way (or makes the values available to something else that messes them up), this can cause UB and daemons and discomfort to users and such. The library expects it is the only one storing values there. In other words, it is expected the trait is only a dumb storage and doesn’t actively do anything.
Required Associated Types§
Required Methods§
sourcefn gen_idx(&self) -> &AtomicUsize
fn gen_idx(&self) -> &AtomicUsize
Access to the generation index.
Must return the same instance of the AtomicUsize
for the lifetime of the storage, must
start at 0
and the trait itself must not modify it. Must be async-signal-safe.
sourcefn shards(&self) -> &Self::Shards
fn shards(&self) -> &Self::Shards
Access to the shards storage.
Must return the same instance of the shards for the lifetime of the storage. Must start zeroed-out and the trait itself must not modify it.
sourcefn choose_shard(&self) -> usize
fn choose_shard(&self) -> usize
Pick one shard of the all selected.
Returns the index of one of the shards. The choice can be arbitrary, but it should be fast and avoid collisions.