velesdb_core/sync.rs
1//! Synchronization primitives with loom support for concurrency testing.
2//!
3//! This module provides type aliases that switch between standard library
4//! sync primitives and loom's mocked versions based on the `loom` feature flag.
5//!
6//! # Usage
7//!
8//! ```rust,no_run
9//! use velesdb_core::sync::{Arc, RwLock, Mutex};
10//!
11//! // Works with both std and loom
12//! let data = Arc::new(RwLock::new(42));
13//! ```
14//!
15//! # Testing with Loom
16//!
17//! ```bash
18//! cargo +nightly test --features loom --test loom_tests
19//! ```
20//!
21//! # EPIC-023: Loom Concurrency Testing
22
23// ============================================================================
24// Arc
25// ============================================================================
26
27#[cfg(loom)]
28pub use loom::sync::Arc;
29
30#[cfg(not(loom))]
31pub use std::sync::Arc;
32
33// ============================================================================
34// Mutex (Note: We use parking_lot in production, but loom provides its own)
35// ============================================================================
36
37#[cfg(loom)]
38pub use loom::sync::Mutex;
39
40#[cfg(not(loom))]
41pub use parking_lot::Mutex;
42
43// ============================================================================
44// RwLock
45// ============================================================================
46
47#[cfg(loom)]
48pub use loom::sync::RwLock;
49
50#[cfg(not(loom))]
51pub use parking_lot::RwLock;
52
53// ============================================================================
54// Atomics
55// ============================================================================
56
57#[cfg(loom)]
58pub use loom::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
59
60#[cfg(not(loom))]
61pub use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
62
63// ============================================================================
64// Thread spawning (for loom tests)
65// ============================================================================
66
67#[cfg(loom)]
68pub use loom::thread;
69
70#[cfg(not(loom))]
71pub use std::thread;