Add try_write to RwLock

This commit is contained in:
John Kåre Alsaker 2018-03-26 20:52:59 +02:00
parent c979189867
commit 962a53d474

View file

@ -388,6 +388,18 @@ impl<T> RwLock<T> {
f(&*self.read())
}
#[cfg(not(parallel_queries))]
#[inline(always)]
pub fn try_write(&self) -> Result<WriteGuard<T>, ()> {
self.0.try_borrow_mut().map_err(|_| ())
}
#[cfg(parallel_queries)]
#[inline(always)]
pub fn try_write(&self) -> Result<WriteGuard<T>, ()> {
self.0.try_write().ok_or(())
}
#[cfg(not(parallel_queries))]
#[inline(always)]
pub fn write(&self) -> WriteGuard<T> {