feat(rand48): rwlock for global params

Signed-off-by: Anhad Singh <andypython@protonmail.com>
This commit is contained in:
Anhad Singh
2024-12-31 01:21:47 +11:00
parent bc51d8e1d5
commit 5eeb59dad2
3 changed files with 37 additions and 15 deletions
+16
View File
@@ -176,6 +176,22 @@ impl<T: ?Sized> RwLock<T> {
self.inner.acquire_write_lock(None);
unsafe { WriteGuard::new(self) }
}
pub fn try_read(&self) -> Option<ReadGuard<'_, T>> {
if self.inner.try_acquire_read_lock().is_ok() {
Some(unsafe { ReadGuard::new(self) })
} else {
None
}
}
pub fn try_write(&self) -> Option<WriteGuard<'_, T>> {
if self.inner.try_acquire_write_lock().is_ok() {
Some(unsafe { WriteGuard::new(self) })
} else {
None
}
}
}
pub struct ReadGuard<'a, T: ?Sized + 'a> {