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§

The type for keeping several shards.

In general, it is expected to be a fixed-size array, but different implementations can have different sizes.

Required Methods§

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.

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.

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.

Implementors§