Skip to content

Commit d40ee40

Browse files
committed
Rollup merge of rust-lang#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
2 parents e957d52 + 71534c4 commit d40ee40

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/libstd/sync/rwlock.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use cell::UnsafeCell;
1212
use fmt;
13-
use marker;
1413
use mem;
1514
use ops::{Deref, DerefMut};
1615
use ptr;
@@ -102,7 +101,10 @@ pub struct RwLockReadGuard<'a, T: ?Sized + 'a> {
102101
}
103102

104103
#[stable(feature = "rust1", since = "1.0.0")]
105-
impl<'a, T: ?Sized> !marker::Send for RwLockReadGuard<'a, T> {}
104+
impl<'a, T: ?Sized> !Send for RwLockReadGuard<'a, T> {}
105+
106+
#[stable(feature = "rwlock_guard_sync", since = "1.23.0")]
107+
unsafe impl<'a, T: ?Sized + Sync> Sync for RwLockReadGuard<'a, T> {}
106108

107109
/// RAII structure used to release the exclusive write access of a lock when
108110
/// dropped.
@@ -121,7 +123,10 @@ pub struct RwLockWriteGuard<'a, T: ?Sized + 'a> {
121123
}
122124

123125
#[stable(feature = "rust1", since = "1.0.0")]
124-
impl<'a, T: ?Sized> !marker::Send for RwLockWriteGuard<'a, T> {}
126+
impl<'a, T: ?Sized> !Send for RwLockWriteGuard<'a, T> {}
127+
128+
#[stable(feature = "rwlock_guard_sync", since = "1.23.0")]
129+
unsafe impl<'a, T: ?Sized + Sync> Sync for RwLockWriteGuard<'a, T> {}
125130

126131
impl<T> RwLock<T> {
127132
/// Creates a new instance of an `RwLock<T>` which is unlocked.

0 commit comments

Comments
 (0)