INNER CODE UNIT · Rust
exclusive_lock
c3rb3ru5d3d53c/binlex · crates/libvex/libvex-rs/src/lib.rs:274
fn exclusive_lock(&self) -> Result<LiftGuard<'_>, LockError> {
let guard = self.0.lock();
if *guard.borrow() != 0 {
return Err(LockError::AlreadyAllocated);
}
*guard.borrow_mut() = 1;
Ok(LiftGuard(guard))
}
fn lock(&self) -> LiftGuard<'_> {
let guard = self.0.lock();
*guard.borrow_mut() += 1;
LiftGuard(guard)
}
}
struct LiftGuard<'a>(ReentrantMutexGuard<'a, RefCell<u8>>);