diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-02-20 12:00:26 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-02-20 12:01:08 -0800 |
| commit | 64fe93e49dc0c6a552c5f08507064f2ce12800ca (patch) | |
| tree | 47b42afb310006fea769a9f02daf236651b55f5c /src/libstd/sys/windows | |
| parent | 522d09dfecbeca1595f25ac58c6d0178bbd21d7d (diff) | |
| download | rust-64fe93e49dc0c6a552c5f08507064f2ce12800ca.tar.gz rust-64fe93e49dc0c6a552c5f08507064f2ce12800ca.zip | |
std: Tidy up some `unsafe impl`s for `sync`
This commit removes many unnecessary `unsafe impl` blocks as well as pushing the needed implementations to the lowest level possible. I noticed that the bounds for `RwLock` are a little off when reviewing #22574 and wanted to ensure that we had our story straight on these implementations.
Diffstat (limited to 'src/libstd/sys/windows')
| -rw-r--r-- | src/libstd/sys/windows/condvar.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sys/windows/mutex.rs | 17 | ||||
| -rw-r--r-- | src/libstd/sys/windows/rwlock.rs | 5 |
3 files changed, 20 insertions, 7 deletions
diff --git a/src/libstd/sys/windows/condvar.rs b/src/libstd/sys/windows/condvar.rs index db8038006fd..071637e3a93 100644 --- a/src/libstd/sys/windows/condvar.rs +++ b/src/libstd/sys/windows/condvar.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::v1::*; + use cell::UnsafeCell; use libc::{self, DWORD}; use os; @@ -17,6 +19,9 @@ use time::Duration; pub struct Condvar { inner: UnsafeCell<ffi::CONDITION_VARIABLE> } +unsafe impl Send for Condvar {} +unsafe impl Sync for Condvar {} + pub const CONDVAR_INIT: Condvar = Condvar { inner: UnsafeCell { value: ffi::CONDITION_VARIABLE_INIT } }; diff --git a/src/libstd/sys/windows/mutex.rs b/src/libstd/sys/windows/mutex.rs index 75495efc7cb..0847f3b52bf 100644 --- a/src/libstd/sys/windows/mutex.rs +++ b/src/libstd/sys/windows/mutex.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use marker::Sync; +use prelude::v1::*; + use cell::UnsafeCell; use sys::sync as ffi; @@ -18,6 +19,7 @@ pub const MUTEX_INIT: Mutex = Mutex { inner: UnsafeCell { value: ffi::SRWLOCK_INIT } }; +unsafe impl Send for Mutex {} unsafe impl Sync for Mutex {} #[inline] @@ -27,14 +29,15 @@ pub unsafe fn raw(m: &Mutex) -> ffi::PSRWLOCK { // So you might be asking why we're using SRWLock instead of CriticalSection? // -// 1. SRWLock is several times faster than CriticalSection according to benchmarks performed on both -// Windows 8 and Windows 7. +// 1. SRWLock is several times faster than CriticalSection according to +// benchmarks performed on both Windows 8 and Windows 7. // -// 2. CriticalSection allows recursive locking while SRWLock deadlocks. The Unix implementation -// deadlocks so consistency is preferred. See #19962 for more details. +// 2. CriticalSection allows recursive locking while SRWLock deadlocks. The Unix +// implementation deadlocks so consistency is preferred. See #19962 for more +// details. // -// 3. While CriticalSection is fair and SRWLock is not, the current Rust policy is there there are -// no guarantees of fairness. +// 3. While CriticalSection is fair and SRWLock is not, the current Rust policy +// is there there are no guarantees of fairness. impl Mutex { #[inline] diff --git a/src/libstd/sys/windows/rwlock.rs b/src/libstd/sys/windows/rwlock.rs index 76fe352ed77..009605535a0 100644 --- a/src/libstd/sys/windows/rwlock.rs +++ b/src/libstd/sys/windows/rwlock.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use prelude::v1::*; + use cell::UnsafeCell; use sys::sync as ffi; @@ -17,6 +19,9 @@ pub const RWLOCK_INIT: RWLock = RWLock { inner: UnsafeCell { value: ffi::SRWLOCK_INIT } }; +unsafe impl Send for RWLock {} +unsafe impl Sync for RWLock {} + impl RWLock { #[inline] pub unsafe fn read(&self) { |
