Struct async_lock::RwLockUpgradableReadGuardArc
source · pub struct RwLockUpgradableReadGuardArc<T: ?Sized> { /* private fields */ }
Expand description
An owned, reference-counting guard that releases the upgradable read lock when dropped.
Implementations§
source§impl<T> RwLockUpgradableReadGuardArc<T>
impl<T> RwLockUpgradableReadGuardArc<T>
sourcepub fn downgrade(guard: Self) -> RwLockReadGuardArc<T>
pub fn downgrade(guard: Self) -> RwLockReadGuardArc<T>
Downgrades into a regular reader guard.
§Examples
use std::sync::Arc;
use async_lock::{RwLock, RwLockUpgradableReadGuardArc};
let lock = Arc::new(RwLock::new(1));
let reader = lock.upgradable_read_arc().await;
assert_eq!(*reader, 1);
assert!(lock.try_upgradable_read_arc().is_none());
let reader = RwLockUpgradableReadGuardArc::downgrade(reader);
assert!(lock.try_upgradable_read_arc().is_some());
source§impl<T: ?Sized> RwLockUpgradableReadGuardArc<T>
impl<T: ?Sized> RwLockUpgradableReadGuardArc<T>
sourcepub fn try_upgrade(guard: Self) -> Result<RwLockWriteGuardArc<T>, Self>
pub fn try_upgrade(guard: Self) -> Result<RwLockWriteGuardArc<T>, Self>
Attempts to upgrade into a write lock.
If a write lock could not be acquired at this time, then None
is returned. Otherwise,
an upgraded guard is returned that releases the write lock when dropped.
This function can only fail if there are other active read locks.
§Examples
use std::sync::Arc;
use async_lock::{RwLock, RwLockUpgradableReadGuardArc};
let lock = Arc::new(RwLock::new(1));
let reader = lock.upgradable_read_arc().await;
assert_eq!(*reader, 1);
let reader2 = lock.read_arc().await;
let reader = RwLockUpgradableReadGuardArc::try_upgrade(reader).unwrap_err();
drop(reader2);
let writer = RwLockUpgradableReadGuardArc::try_upgrade(reader).unwrap();
sourcepub fn upgrade(guard: Self) -> UpgradeArc<T> ⓘ
pub fn upgrade(guard: Self) -> UpgradeArc<T> ⓘ
Upgrades into a write lock.
§Examples
use std::sync::Arc;
use async_lock::{RwLock, RwLockUpgradableReadGuardArc};
let lock = Arc::new(RwLock::new(1));
let reader = lock.upgradable_read_arc().await;
assert_eq!(*reader, 1);
let mut writer = RwLockUpgradableReadGuardArc::upgrade(reader).await;
*writer = 2;
sourcepub fn upgrade_blocking(guard: Self) -> RwLockWriteGuardArc<T>
pub fn upgrade_blocking(guard: Self) -> RwLockWriteGuardArc<T>
Upgrades into a write lock.
§Blocking
This function will block the current thread until it is able to acquire the write lock.
§Examples
use std::sync::Arc;
use async_lock::{RwLock, RwLockUpgradableReadGuardArc};
let lock = Arc::new(RwLock::new(1));
let reader = lock.upgradable_read_arc_blocking();
assert_eq!(*reader, 1);
let mut writer = RwLockUpgradableReadGuardArc::upgrade_blocking(reader);
*writer = 2;
Trait Implementations§
source§impl<T: ?Sized> Deref for RwLockUpgradableReadGuardArc<T>
impl<T: ?Sized> Deref for RwLockUpgradableReadGuardArc<T>
source§impl<T: ?Sized> Drop for RwLockUpgradableReadGuardArc<T>
impl<T: ?Sized> Drop for RwLockUpgradableReadGuardArc<T>
impl<T: Send + Sync + ?Sized> Send for RwLockUpgradableReadGuardArc<T>
impl<T: Send + Sync + ?Sized> Sync for RwLockUpgradableReadGuardArc<T>
Auto Trait Implementations§
impl<T> Freeze for RwLockUpgradableReadGuardArc<T>where
T: ?Sized,
impl<T> !RefUnwindSafe for RwLockUpgradableReadGuardArc<T>
impl<T> Unpin for RwLockUpgradableReadGuardArc<T>where
T: ?Sized,
impl<T> !UnwindSafe for RwLockUpgradableReadGuardArc<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more