From fff5600925cf3bbee2befd6957b727016765ebd0 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Sun, 25 Jan 2015 23:54:09 +0100 Subject: [PATCH 1/2] Make Unix and Windows impls consistent There are some explicit Send/Sync implementations for Window's types that don't exist in Unix. While the end result will be the same, I believe it's clearer if we keep the explicit implementations consistent by making the os-specific types Send/Sync where needed and possible. This commit addresses pipe src/libstd/sys/unix/pipe.rs unsafe impl Send for UnixListener {} unsafe impl Sync for UnixListener {} src/libstd/sys/windows/pipe.rs unsafe impl Send for UnixStream {} unsafe impl Sync for UnixStream {} unsafe impl Send for UnixListener {} unsafe impl Sync for UnixListener {} unsafe impl Send for UnixAcceptor {} unsafe impl Sync for UnixAcceptor {} unsafe impl Send for AcceptorState {} unsafe impl Sync for AcceptorState {} --- src/libstd/sys/windows/pipe.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs index 9996909f2f5..ef511d13199 100644 --- a/src/libstd/sys/windows/pipe.rs +++ b/src/libstd/sys/windows/pipe.rs @@ -129,6 +129,9 @@ impl Drop for Event { } } +unsafe impl Send for Event {} +unsafe impl Sync for Event {} + struct Inner { handle: libc::HANDLE, lock: Mutex<()>, @@ -156,6 +159,9 @@ impl Drop for Inner { } } +unsafe impl Send for Inner {} +unsafe impl Sync for Inner {} + unsafe fn pipe(name: *const u16, init: bool) -> libc::HANDLE { libc::CreateNamedPipeW( name, @@ -220,9 +226,6 @@ pub struct UnixStream { write_deadline: u64, } -unsafe impl Send for UnixStream {} -unsafe impl Sync for UnixStream {} - impl UnixStream { fn try_connect(p: *const u16) -> Option { // Note that most of this is lifted from the libuv implementation. @@ -615,17 +618,11 @@ pub struct UnixAcceptor { deadline: u64, } -unsafe impl Send for UnixAcceptor {} -unsafe impl Sync for UnixAcceptor {} - struct AcceptorState { abort: Event, closed: AtomicBool, } -unsafe impl Send for AcceptorState {} -unsafe impl Sync for AcceptorState {} - impl UnixAcceptor { pub fn accept(&mut self) -> IoResult { // This function has some funky implementation details when working with From fde4472848b662a4d1236388c4cf15e2450237e6 Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Mon, 26 Jan 2015 00:06:12 +0100 Subject: [PATCH 2/2] Make Unix and Windows impls consistent There are some explicit Send/Sync implementations for Window's types that don't exist in Unix. While the end result will be the same, I believe it's clearer if we keep the explicit implementations consistent by making the os-specific types Send/Sync where needed and possible. This commit addresses tcp. Existing differences below: src/libstd/sys/unix/tcp.rs unsafe impl Sync for TcpListener {} unsafe impl Sync for AcceptorInner {} src/libstd/sys/windows/tcp.rs unsafe impl Send for Event {} unsafe impl Sync for Event {} unsafe impl Send for TcpListener {} unsafe impl Sync for TcpListener {} unsafe impl Send for TcpAcceptor {} unsafe impl Sync for TcpAcceptor {} unsafe impl Send for AcceptorInner {} unsafe impl Sync for AcceptorInner {} --- src/libstd/sys/windows/tcp.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libstd/sys/windows/tcp.rs b/src/libstd/sys/windows/tcp.rs index 77139b52efa..ebebeb1a8a5 100644 --- a/src/libstd/sys/windows/tcp.rs +++ b/src/libstd/sys/windows/tcp.rs @@ -116,9 +116,6 @@ pub struct TcpAcceptor { deadline: u64, } -unsafe impl Send for TcpAcceptor {} -unsafe impl Sync for TcpAcceptor {} - struct AcceptorInner { listener: TcpListener, abort: Event, @@ -126,7 +123,6 @@ struct AcceptorInner { closed: AtomicBool, } -unsafe impl Send for AcceptorInner {} unsafe impl Sync for AcceptorInner {} impl TcpAcceptor {