Rollup merge of #45682 - RalfJung:rwlock-guards, r=alexcrichton
RwLock guards are Sync if T is Currently, the compiler requires `T` to also be `Send`. There is no reason for that. `&Rw{Read,Write}LockGuard` only provides a shared referenced to `T`, sending that across threads is safe if `T` is `Sync`. Cc @oconnor663
This commit is contained in:
commit
eae36714df
1 changed files with 8 additions and 3 deletions
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
use cell::UnsafeCell;
|
use cell::UnsafeCell;
|
||||||
use fmt;
|
use fmt;
|
||||||
use marker;
|
|
||||||
use mem;
|
use mem;
|
||||||
use ops::{Deref, DerefMut};
|
use ops::{Deref, DerefMut};
|
||||||
use ptr;
|
use ptr;
|
||||||
|
@ -102,7 +101,10 @@ pub struct RwLockReadGuard<'a, T: ?Sized + 'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<'a, T: ?Sized> !marker::Send for RwLockReadGuard<'a, T> {}
|
impl<'a, T: ?Sized> !Send for RwLockReadGuard<'a, T> {}
|
||||||
|
|
||||||
|
#[stable(feature = "rwlock_guard_sync", since = "1.23.0")]
|
||||||
|
unsafe impl<'a, T: ?Sized + Sync> Sync for RwLockReadGuard<'a, T> {}
|
||||||
|
|
||||||
/// RAII structure used to release the exclusive write access of a lock when
|
/// RAII structure used to release the exclusive write access of a lock when
|
||||||
/// dropped.
|
/// dropped.
|
||||||
|
@ -121,7 +123,10 @@ pub struct RwLockWriteGuard<'a, T: ?Sized + 'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<'a, T: ?Sized> !marker::Send for RwLockWriteGuard<'a, T> {}
|
impl<'a, T: ?Sized> !Send for RwLockWriteGuard<'a, T> {}
|
||||||
|
|
||||||
|
#[stable(feature = "rwlock_guard_sync", since = "1.23.0")]
|
||||||
|
unsafe impl<'a, T: ?Sized + Sync> Sync for RwLockWriteGuard<'a, T> {}
|
||||||
|
|
||||||
impl<T> RwLock<T> {
|
impl<T> RwLock<T> {
|
||||||
/// Creates a new instance of an `RwLock<T>` which is unlocked.
|
/// Creates a new instance of an `RwLock<T>` which is unlocked.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue