Skip to content

Commit

Permalink
Rollup merge of rust-lang#45682 - RalfJung:rwlock-guards, r=alexcrichton
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kennytm committed Nov 7, 2017
2 parents e957d52 + 71534c4 commit d40ee40
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/libstd/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use cell::UnsafeCell;
use fmt;
use marker;
use mem;
use ops::{Deref, DerefMut};
use ptr;
Expand Down Expand Up @@ -102,7 +101,10 @@ pub struct RwLockReadGuard<'a, T: ?Sized + 'a> {
}

#[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
/// dropped.
Expand All @@ -121,7 +123,10 @@ pub struct RwLockWriteGuard<'a, T: ?Sized + 'a> {
}

#[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> {
/// Creates a new instance of an `RwLock<T>` which is unlocked.
Expand Down

0 comments on commit d40ee40

Please sign in to comment.