diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2018-03-26 20:52:59 +0200 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2018-03-28 01:27:59 +0200 |
| commit | 962a53d4741e4e2e514f49d9b13831f3cd4e7b48 (patch) | |
| tree | 7e1ce9ef5db00390265868e74536f92a6160e540 /src/librustc_data_structures | |
| parent | c979189867d4af957a50cd4ad39c230dc06344f9 (diff) | |
| download | rust-962a53d4741e4e2e514f49d9b13831f3cd4e7b48.tar.gz rust-962a53d4741e4e2e514f49d9b13831f3cd4e7b48.zip | |
Add try_write to RwLock
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/sync.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index 184ef136976..0f534f0adec 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -390,6 +390,18 @@ impl<T> RwLock<T> { #[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> { self.0.borrow_mut() } |
