pub struct LfrLock<T: 'static> { /* private fields */ }Expand description
LfrLock (Lock-Free Read Lock) - Reads never block, writes are serialized using Mutex
Similar to std::sync::Mutex, a unified type supports both read and write operations.
Core features: Read operations are lock-free and never block; write operations involve copying old data, modifying, and then atomically replacing.
LfrLock (Lock-Free Read Lock) - 读取永不阻塞,写入使用 Mutex 串行化
类似于 std::sync::Mutex,统一的类型同时支持读写操作。
核心特性:读取操作无锁且永不阻塞;写入操作涉及复制旧数据、修改、然后原子替换。
Implementations§
Source§impl<T: 'static> LfrLock<T>
impl<T: 'static> LfrLock<T>
Sourcepub fn write_with<F>(&self, f: F)
pub fn write_with<F>(&self, f: F)
Write operation (closure style)
写入操作(闭包方式)
Sourcepub fn write(&self) -> WriteGuard<'_, T>where
T: Clone,
pub fn write(&self) -> WriteGuard<'_, T>where
T: Clone,
Write operation (Guard style) - Requires T to implement Clone
Returns WriteGuard, allowing direct data modification, automatically committed on drop. Acquires Mutex lock to ensure serialized writes.
写入操作(Guard 方式)- 需要 T 实现 Clone
返回 WriteGuard,允许直接修改数据,在 drop 时自动提交。 获取 Mutex 锁,确保串行化写入。
Sourcepub fn try_write(&self) -> Option<WriteGuard<'_, T>>where
T: Clone,
pub fn try_write(&self) -> Option<WriteGuard<'_, T>>where
T: Clone,
Try to acquire write lock
尝试获取写入锁