pub struct Lock<'a> { /* private fields */ }Expand description
A sophisticated lock implementation designed for concurrent cuckoo filter operations.
This is NOT a traditional mutex but an atomic-based synchronization mechanism that enables three distinct concurrency modes:
-
Optimistic locks: Allow maximum concurrency - multiple readers and writers can proceed simultaneously. Used for optimistic reads that detect data races.
-
WriterExclusive locks: Mutual exclusion among writers only - prevents concurrent modifications but allows concurrent reads.
-
FullyExclusive locks: Complete mutual exclusion - blocks all operations. Only used during complex eviction chains to ensure consistency.
§Version Encoding Scheme
The atomic usize encodes both lock state and version information:
- Bits 0-1: Lock kind (0=Optimistic, 1=WriterExclusive, 2=FullyExclusive)
- Bits 2-63: Version counter (incremented on FullyExclusive release)
This allows optimistic readers to detect when their read might be stale by comparing version numbers before and after the operation.