moirai-utils 0.7.0

Utility functions and data structures for Moirai concurrency library
Documentation

moirai-utils

crates.io docs.rs

Low-level utilities shared across the Moirai concurrency library, organized by domain:

  • cache — CacheAligned<T> (#[repr(align(64))]), align_to_cache_line, CACHE_LINE_SIZE.
  • atomic — AtomicCounter for lock-free counting.
  • queue — LockFreeQueue.
  • memory — prefetch_read / prefetch_write.
  • simd — SimdScalar / SimdReal and has_native_vector_path.
[dependencies]
moirai-utils = "0.5"
use moirai_utils::{AtomicCounter, CacheAligned};
use std::mem::align_of;
use std::sync::atomic::AtomicUsize;

// Keep two hot indices off one cache line to avoid false sharing.
struct Ring {
    head: CacheAligned<AtomicUsize>,
    tail: CacheAligned<AtomicUsize>,
}
assert_eq!(align_of::<CacheAligned<AtomicUsize>>(), 64);
let _ring = Ring {
    head: CacheAligned::new(AtomicUsize::new(0)),
    tail: CacheAligned::new(AtomicUsize::new(0)),
};

let counter = AtomicCounter::new();
assert_eq!(counter.increment(), 0); // returns the previous value
assert_eq!(counter.get(), 1);

Full documentation: https://docs.rs/moirai-utils

License

Licensed under either of Apache-2.0 or MIT at your option.