Auto merge of #25136 - alexcrichton:drop-the-two, r=aturon
* Remove the 2-suffix from some modules * Remove some unused files * Remove double-boxing for `ReentrantMutex`
This commit is contained in:
commit
cf76e63745
@ -23,7 +23,7 @@ use fmt;
|
||||
use ffi::OsString;
|
||||
use io::{self, Error, ErrorKind, SeekFrom, Seek, Read, Write};
|
||||
use path::{Path, PathBuf};
|
||||
use sys::fs2 as fs_imp;
|
||||
use sys::fs as fs_imp;
|
||||
use sys_common::{AsInnerMut, FromInner, AsInner};
|
||||
use vec::Vec;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
use prelude::v1::*;
|
||||
|
||||
use io::{self, Error, ErrorKind};
|
||||
use sys_common::net2 as net_imp;
|
||||
use sys_common::net as net_imp;
|
||||
|
||||
pub use self::ip::{IpAddr, Ipv4Addr, Ipv6Addr, Ipv6MulticastScope};
|
||||
pub use self::addr::{SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
|
||||
|
@ -17,7 +17,7 @@ use io::prelude::*;
|
||||
use fmt;
|
||||
use io;
|
||||
use net::{ToSocketAddrs, SocketAddr, Shutdown};
|
||||
use sys_common::net2 as net_imp;
|
||||
use sys_common::net as net_imp;
|
||||
use sys_common::{AsInner, FromInner};
|
||||
|
||||
/// A structure which represents a TCP stream between a local socket and a
|
||||
|
@ -16,7 +16,7 @@ use prelude::v1::*;
|
||||
use fmt;
|
||||
use io::{self, Error, ErrorKind};
|
||||
use net::{ToSocketAddrs, SocketAddr, IpAddr};
|
||||
use sys_common::net2 as net_imp;
|
||||
use sys_common::net as net_imp;
|
||||
use sys_common::{AsInner, FromInner};
|
||||
|
||||
/// A User Datagram Protocol socket.
|
||||
|
@ -15,5 +15,5 @@
|
||||
pub mod raw;
|
||||
|
||||
pub mod fs {
|
||||
pub use sys::fs2::MetadataExt;
|
||||
pub use sys::fs::MetadataExt;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@
|
||||
pub mod raw;
|
||||
|
||||
pub mod fs {
|
||||
pub use sys::fs2::MetadataExt;
|
||||
pub use sys::fs::MetadataExt;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@
|
||||
pub mod raw;
|
||||
|
||||
pub mod fs {
|
||||
pub use sys::fs2::MetadataExt;
|
||||
pub use sys::fs::MetadataExt;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@
|
||||
pub mod raw;
|
||||
|
||||
pub mod fs {
|
||||
pub use sys::fs2::MetadataExt;
|
||||
pub use sys::fs::MetadataExt;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@
|
||||
pub mod raw;
|
||||
|
||||
pub mod fs {
|
||||
pub use sys::fs2::MetadataExt;
|
||||
pub use sys::fs::MetadataExt;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@
|
||||
pub mod raw;
|
||||
|
||||
pub mod fs {
|
||||
pub use sys::fs2::MetadataExt;
|
||||
pub use sys::fs::MetadataExt;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@
|
||||
pub mod raw;
|
||||
|
||||
pub mod fs {
|
||||
pub use sys::fs2::MetadataExt;
|
||||
pub use sys::fs::MetadataExt;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@
|
||||
pub mod raw;
|
||||
|
||||
pub mod fs {
|
||||
pub use sys::fs2::MetadataExt;
|
||||
pub use sys::fs::MetadataExt;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@
|
||||
pub mod raw;
|
||||
|
||||
pub mod fs {
|
||||
pub use sys::fs2::MetadataExt;
|
||||
pub use sys::fs::MetadataExt;
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ use fmt;
|
||||
use io::{self, Error, ErrorKind};
|
||||
use path;
|
||||
use sync::mpsc::{channel, Receiver};
|
||||
use sys::pipe2::{self, AnonPipe};
|
||||
use sys::process2::Command as CommandImp;
|
||||
use sys::process2::Process as ProcessImp;
|
||||
use sys::process2::ExitStatus as ExitStatusImp;
|
||||
use sys::process2::Stdio as StdioImp2;
|
||||
use sys::pipe::{self, AnonPipe};
|
||||
use sys::process::Command as CommandImp;
|
||||
use sys::process::Process as ProcessImp;
|
||||
use sys::process::ExitStatus as ExitStatusImp;
|
||||
use sys::process::Stdio as StdioImp2;
|
||||
use sys_common::{AsInner, AsInnerMut};
|
||||
use thread;
|
||||
|
||||
@ -334,7 +334,7 @@ fn setup_io(io: &StdioImp, readable: bool)
|
||||
Null => (StdioImp2::None, None),
|
||||
Inherit => (StdioImp2::Inherit, None),
|
||||
Piped => {
|
||||
let (reader, writer) = try!(pipe2::anon_pipe());
|
||||
let (reader, writer) = try!(pipe::anon_pipe());
|
||||
if readable {
|
||||
(StdioImp2::Piped(reader), Some(writer))
|
||||
} else {
|
||||
|
@ -1,170 +0,0 @@
|
||||
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Implementation of the helper thread for the timer module
|
||||
//!
|
||||
//! This module contains the management necessary for the timer worker thread.
|
||||
//! This thread is responsible for performing the send()s on channels for timers
|
||||
//! that are using channels instead of a blocking call.
|
||||
//!
|
||||
//! The timer thread is lazily initialized, and it's shut down via the
|
||||
//! `shutdown` function provided. It must be maintained as an invariant that
|
||||
//! `shutdown` is only called when the entire program is finished. No new timers
|
||||
//! can be created in the future and there must be no active timers at that
|
||||
//! time.
|
||||
|
||||
use prelude::v1::*;
|
||||
|
||||
use boxed;
|
||||
use cell::UnsafeCell;
|
||||
use rt;
|
||||
use sync::{StaticMutex, StaticCondvar};
|
||||
use sync::mpsc::{channel, Sender, Receiver};
|
||||
use sys::helper_signal;
|
||||
|
||||
use thread;
|
||||
|
||||
/// A structure for management of a helper thread.
|
||||
///
|
||||
/// This is generally a static structure which tracks the lifetime of a helper
|
||||
/// thread.
|
||||
///
|
||||
/// The fields of this helper are all public, but they should not be used, this
|
||||
/// is for static initialization.
|
||||
pub struct Helper<M:Send> {
|
||||
/// Internal lock which protects the remaining fields
|
||||
pub lock: StaticMutex,
|
||||
pub cond: StaticCondvar,
|
||||
|
||||
// You'll notice that the remaining fields are UnsafeCell<T>, and this is
|
||||
// because all helper thread operations are done through &self, but we need
|
||||
// these to be mutable (once `lock` is held).
|
||||
|
||||
/// Lazily allocated channel to send messages to the helper thread.
|
||||
pub chan: UnsafeCell<*mut Sender<M>>,
|
||||
|
||||
/// OS handle used to wake up a blocked helper thread
|
||||
pub signal: UnsafeCell<usize>,
|
||||
|
||||
/// Flag if this helper thread has booted and been initialized yet.
|
||||
pub initialized: UnsafeCell<bool>,
|
||||
|
||||
/// Flag if this helper thread has shut down
|
||||
pub shutdown: UnsafeCell<bool>,
|
||||
}
|
||||
|
||||
unsafe impl<M:Send> Send for Helper<M> { }
|
||||
|
||||
unsafe impl<M:Send> Sync for Helper<M> { }
|
||||
|
||||
struct RaceBox(helper_signal::signal);
|
||||
|
||||
unsafe impl Send for RaceBox {}
|
||||
unsafe impl Sync for RaceBox {}
|
||||
|
||||
macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => (
|
||||
static $name: Helper<$m> = Helper {
|
||||
lock: ::sync::MUTEX_INIT,
|
||||
cond: ::sync::CONDVAR_INIT,
|
||||
chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
|
||||
signal: ::cell::UnsafeCell { value: 0 },
|
||||
initialized: ::cell::UnsafeCell { value: false },
|
||||
shutdown: ::cell::UnsafeCell { value: false },
|
||||
};
|
||||
) }
|
||||
|
||||
impl<M: Send> Helper<M> {
|
||||
/// Lazily boots a helper thread, becoming a no-op if the helper has already
|
||||
/// been spawned.
|
||||
///
|
||||
/// This function will check to see if the thread has been initialized, and
|
||||
/// if it has it returns quickly. If initialization has not happened yet,
|
||||
/// the closure `f` will be run (inside of the initialization lock) and
|
||||
/// passed to the helper thread in a separate task.
|
||||
///
|
||||
/// This function is safe to be called many times.
|
||||
pub fn boot<T, F>(&'static self, f: F, helper: fn(helper_signal::signal, Receiver<M>, T)) where
|
||||
T: Send + 'static,
|
||||
F: FnOnce() -> T,
|
||||
{
|
||||
unsafe {
|
||||
let _guard = self.lock.lock().unwrap();
|
||||
if *self.chan.get() as usize == 0 {
|
||||
let (tx, rx) = channel();
|
||||
*self.chan.get() = boxed::into_raw(box tx);
|
||||
let (receive, send) = helper_signal::new();
|
||||
*self.signal.get() = send as usize;
|
||||
|
||||
let receive = RaceBox(receive);
|
||||
|
||||
let t = f();
|
||||
thread::spawn(move || {
|
||||
helper(receive.0, rx, t);
|
||||
let _g = self.lock.lock().unwrap();
|
||||
*self.shutdown.get() = true;
|
||||
self.cond.notify_one()
|
||||
});
|
||||
|
||||
let _ = rt::at_exit(move || { self.shutdown() });
|
||||
*self.initialized.get() = true;
|
||||
} else if *self.chan.get() as usize == 1 {
|
||||
panic!("cannot continue usage after shutdown");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends a message to a spawned worker thread.
|
||||
///
|
||||
/// This is only valid if the worker thread has previously booted
|
||||
pub fn send(&'static self, msg: M) {
|
||||
unsafe {
|
||||
let _guard = self.lock.lock().unwrap();
|
||||
|
||||
// Must send and *then* signal to ensure that the child receives the
|
||||
// message. Otherwise it could wake up and go to sleep before we
|
||||
// send the message.
|
||||
assert!(*self.chan.get() as usize != 0);
|
||||
assert!(*self.chan.get() as usize != 1,
|
||||
"cannot continue usage after shutdown");
|
||||
(**self.chan.get()).send(msg).unwrap();
|
||||
helper_signal::signal(*self.signal.get() as helper_signal::signal);
|
||||
}
|
||||
}
|
||||
|
||||
fn shutdown(&'static self) {
|
||||
unsafe {
|
||||
// Shut down, but make sure this is done inside our lock to ensure
|
||||
// that we'll always receive the exit signal when the thread
|
||||
// returns.
|
||||
let mut guard = self.lock.lock().unwrap();
|
||||
|
||||
let ptr = *self.chan.get();
|
||||
if ptr as usize == 1 {
|
||||
panic!("cannot continue usage after shutdown");
|
||||
}
|
||||
// Close the channel by destroying it
|
||||
let chan = Box::from_raw(*self.chan.get());
|
||||
*self.chan.get() = 1 as *mut Sender<M>;
|
||||
drop(chan);
|
||||
helper_signal::signal(*self.signal.get() as helper_signal::signal);
|
||||
|
||||
// Wait for the child to exit
|
||||
while !*self.shutdown.get() {
|
||||
guard = self.cond.wait(guard).unwrap();
|
||||
}
|
||||
drop(guard);
|
||||
|
||||
// Clean up after ourselves
|
||||
self.lock.destroy();
|
||||
helper_signal::close(*self.signal.get() as helper_signal::signal);
|
||||
*self.signal.get() = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ use prelude::v1::*;
|
||||
pub mod backtrace;
|
||||
pub mod condvar;
|
||||
pub mod mutex;
|
||||
pub mod net2;
|
||||
pub mod net;
|
||||
pub mod poison;
|
||||
pub mod remutex;
|
||||
pub mod rwlock;
|
||||
|
@ -19,9 +19,9 @@ use sys::mutex as sys;
|
||||
|
||||
/// A re-entrant mutual exclusion
|
||||
///
|
||||
/// This mutex will block *other* threads waiting for the lock to become available. The thread
|
||||
/// which has already locked the mutex can lock it multiple times without blocking, preventing a
|
||||
/// common source of deadlocks.
|
||||
/// This mutex will block *other* threads waiting for the lock to become
|
||||
/// available. The thread which has already locked the mutex can lock it
|
||||
/// multiple times without blocking, preventing a common source of deadlocks.
|
||||
pub struct ReentrantMutex<T> {
|
||||
inner: Box<sys::ReentrantMutex>,
|
||||
poison: poison::Flag,
|
||||
@ -51,10 +51,14 @@ impl<'a, T> !marker::Send for ReentrantMutexGuard<'a, T> {}
|
||||
impl<T> ReentrantMutex<T> {
|
||||
/// Creates a new reentrant mutex in an unlocked state.
|
||||
pub fn new(t: T) -> ReentrantMutex<T> {
|
||||
ReentrantMutex {
|
||||
inner: box unsafe { sys::ReentrantMutex::new() },
|
||||
poison: poison::FLAG_INIT,
|
||||
data: t,
|
||||
unsafe {
|
||||
let mut mutex = ReentrantMutex {
|
||||
inner: box sys::ReentrantMutex::uninitialized(),
|
||||
poison: poison::FLAG_INIT,
|
||||
data: t,
|
||||
};
|
||||
mutex.inner.init();
|
||||
return mutex
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ impl OpenOptionsExt for OpenOptions {
|
||||
}
|
||||
|
||||
#[unstable(feature = "metadata_ext", reason = "recently added API")]
|
||||
pub struct Metadata(sys::fs2::FileAttr);
|
||||
pub struct Metadata(sys::fs::FileAttr);
|
||||
|
||||
#[unstable(feature = "metadata_ext", reason = "recently added API")]
|
||||
pub trait MetadataExt {
|
||||
@ -111,7 +111,7 @@ pub trait MetadataExt {
|
||||
|
||||
impl MetadataExt for fs::Metadata {
|
||||
fn as_raw(&self) -> &Metadata {
|
||||
let inner: &sys::fs2::FileAttr = self.as_inner();
|
||||
let inner: &sys::fs::FileAttr = self.as_inner();
|
||||
unsafe { mem::transmute(inner) }
|
||||
}
|
||||
}
|
||||
@ -187,7 +187,7 @@ impl DirEntryExt for fs::DirEntry {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()>
|
||||
{
|
||||
sys::fs2::symlink(src.as_ref(), dst.as_ref())
|
||||
sys::fs::symlink(src.as_ref(), dst.as_ref())
|
||||
}
|
||||
|
||||
#[unstable(feature = "dir_builder", reason = "recently added API")]
|
||||
|
@ -16,7 +16,7 @@ use fs;
|
||||
use net;
|
||||
use os::raw;
|
||||
use sys;
|
||||
use sys_common::{net2, AsInner, FromInner};
|
||||
use sys_common::{self, AsInner, FromInner};
|
||||
|
||||
/// Raw file descriptors.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@ -68,7 +68,7 @@ impl AsRawFd for fs::File {
|
||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||
impl FromRawFd for fs::File {
|
||||
unsafe fn from_raw_fd(fd: RawFd) -> fs::File {
|
||||
fs::File::from_inner(sys::fs2::File::from_inner(fd))
|
||||
fs::File::from_inner(sys::fs::File::from_inner(fd))
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,20 +89,20 @@ impl AsRawFd for net::UdpSocket {
|
||||
impl FromRawFd for net::TcpStream {
|
||||
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
|
||||
let socket = sys::net::Socket::from_inner(fd);
|
||||
net::TcpStream::from_inner(net2::TcpStream::from_inner(socket))
|
||||
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(socket))
|
||||
}
|
||||
}
|
||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||
impl FromRawFd for net::TcpListener {
|
||||
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
|
||||
let socket = sys::net::Socket::from_inner(fd);
|
||||
net::TcpListener::from_inner(net2::TcpListener::from_inner(socket))
|
||||
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(socket))
|
||||
}
|
||||
}
|
||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||
impl FromRawFd for net::UdpSocket {
|
||||
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
|
||||
let socket = sys::net::Socket::from_inner(fd);
|
||||
net::UdpSocket::from_inner(net2::UdpSocket::from_inner(socket))
|
||||
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(socket))
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ pub trait ExitStatusExt {
|
||||
impl ExitStatusExt for process::ExitStatus {
|
||||
fn signal(&self) -> Option<i32> {
|
||||
match *self.as_inner() {
|
||||
sys::process2::ExitStatus::Signal(s) => Some(s),
|
||||
sys::process::ExitStatus::Signal(s) => Some(s),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
@ -33,13 +33,13 @@ pub mod c;
|
||||
pub mod condvar;
|
||||
pub mod ext;
|
||||
pub mod fd;
|
||||
pub mod fs2;
|
||||
pub mod fs;
|
||||
pub mod mutex;
|
||||
pub mod net;
|
||||
pub mod os;
|
||||
pub mod os_str;
|
||||
pub mod pipe2;
|
||||
pub mod process2;
|
||||
pub mod pipe;
|
||||
pub mod process;
|
||||
pub mod rwlock;
|
||||
pub mod stack_overflow;
|
||||
pub mod sync;
|
||||
|
@ -69,30 +69,27 @@ impl Mutex {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: remove the box, because box happens twice now, once at the common layer and once here.
|
||||
// Box is necessary here, because mutex may not change address after it is intialised on some
|
||||
// platforms. Regular Mutex above handles this by offloading intialisation to the OS on first lock.
|
||||
// Sadly, as far as reentrant mutexes go, this scheme is not quite portable and we must initialise
|
||||
// when we create the mutex, in the `new`.
|
||||
pub struct ReentrantMutex { inner: Box<UnsafeCell<ffi::pthread_mutex_t>> }
|
||||
pub struct ReentrantMutex { inner: UnsafeCell<ffi::pthread_mutex_t> }
|
||||
|
||||
unsafe impl Send for ReentrantMutex {}
|
||||
unsafe impl Sync for ReentrantMutex {}
|
||||
|
||||
impl ReentrantMutex {
|
||||
pub unsafe fn new() -> ReentrantMutex {
|
||||
let mutex = ReentrantMutex { inner: box mem::uninitialized() };
|
||||
pub unsafe fn uninitialized() -> ReentrantMutex {
|
||||
ReentrantMutex { inner: mem::uninitialized() }
|
||||
}
|
||||
|
||||
pub unsafe fn init(&mut self) {
|
||||
let mut attr: ffi::pthread_mutexattr_t = mem::uninitialized();
|
||||
let result = ffi::pthread_mutexattr_init(&mut attr as *mut _);
|
||||
debug_assert_eq!(result, 0);
|
||||
let result = ffi::pthread_mutexattr_settype(&mut attr as *mut _,
|
||||
ffi::PTHREAD_MUTEX_RECURSIVE);
|
||||
debug_assert_eq!(result, 0);
|
||||
let result = ffi::pthread_mutex_init(mutex.inner.get(), &attr as *const _);
|
||||
let result = ffi::pthread_mutex_init(self.inner.get(), &attr as *const _);
|
||||
debug_assert_eq!(result, 0);
|
||||
let result = ffi::pthread_mutexattr_destroy(&mut attr as *mut _);
|
||||
debug_assert_eq!(result, 0);
|
||||
mutex
|
||||
}
|
||||
|
||||
pub unsafe fn lock(&self) {
|
||||
|
@ -18,9 +18,9 @@ use fmt;
|
||||
use io::{self, Error, ErrorKind};
|
||||
use libc::{self, pid_t, c_void, c_int, gid_t, uid_t};
|
||||
use ptr;
|
||||
use sys::pipe2::AnonPipe;
|
||||
use sys::pipe::AnonPipe;
|
||||
use sys::{self, c, cvt, cvt_r};
|
||||
use sys::fs2::{File, OpenOptions};
|
||||
use sys::fs::{File, OpenOptions};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Command
|
||||
@ -141,7 +141,7 @@ impl Process {
|
||||
|
||||
let (envp, _a, _b) = make_envp(cfg.env.as_ref());
|
||||
let (argv, _a) = make_argv(&cfg.program, &cfg.args);
|
||||
let (input, output) = try!(sys::pipe2::anon_pipe());
|
||||
let (input, output) = try!(sys::pipe::anon_pipe());
|
||||
|
||||
let pid = unsafe {
|
||||
match libc::fork() {
|
@ -125,7 +125,7 @@ impl MetadataExt for Metadata {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q)
|
||||
-> io::Result<()> {
|
||||
sys::fs2::symlink_inner(src.as_ref(), dst.as_ref(), false)
|
||||
sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), false)
|
||||
}
|
||||
|
||||
/// Creates a new directory symlink on the filesystem.
|
||||
@ -146,5 +146,5 @@ pub fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q)
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn symlink_dir<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q)
|
||||
-> io::Result<()> {
|
||||
sys::fs2::symlink_inner(src.as_ref(), dst.as_ref(), true)
|
||||
sys::fs::symlink_inner(src.as_ref(), dst.as_ref(), true)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
use fs;
|
||||
use os::windows::raw;
|
||||
use net;
|
||||
use sys_common::{net2, AsInner, FromInner};
|
||||
use sys_common::{self, AsInner, FromInner};
|
||||
use sys;
|
||||
|
||||
/// Raw HANDLEs.
|
||||
@ -61,7 +61,7 @@ impl AsRawHandle for fs::File {
|
||||
impl FromRawHandle for fs::File {
|
||||
unsafe fn from_raw_handle(handle: RawHandle) -> fs::File {
|
||||
let handle = handle as ::libc::HANDLE;
|
||||
fs::File::from_inner(sys::fs2::File::from_inner(handle))
|
||||
fs::File::from_inner(sys::fs::File::from_inner(handle))
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,20 +113,20 @@ impl AsRawSocket for net::UdpSocket {
|
||||
impl FromRawSocket for net::TcpStream {
|
||||
unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpStream {
|
||||
let sock = sys::net::Socket::from_inner(sock);
|
||||
net::TcpStream::from_inner(net2::TcpStream::from_inner(sock))
|
||||
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(sock))
|
||||
}
|
||||
}
|
||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||
impl FromRawSocket for net::TcpListener {
|
||||
unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpListener {
|
||||
let sock = sys::net::Socket::from_inner(sock);
|
||||
net::TcpListener::from_inner(net2::TcpListener::from_inner(sock))
|
||||
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(sock))
|
||||
}
|
||||
}
|
||||
#[stable(feature = "from_raw_os", since = "1.1.0")]
|
||||
impl FromRawSocket for net::UdpSocket {
|
||||
unsafe fn from_raw_socket(sock: RawSocket) -> net::UdpSocket {
|
||||
let sock = sys::net::Socket::from_inner(sock);
|
||||
net::UdpSocket::from_inner(net2::UdpSocket::from_inner(sock))
|
||||
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(sock))
|
||||
}
|
||||
}
|
||||
|
@ -25,14 +25,14 @@ pub mod backtrace;
|
||||
pub mod c;
|
||||
pub mod condvar;
|
||||
pub mod ext;
|
||||
pub mod fs2;
|
||||
pub mod fs;
|
||||
pub mod handle;
|
||||
pub mod mutex;
|
||||
pub mod net;
|
||||
pub mod os;
|
||||
pub mod os_str;
|
||||
pub mod pipe2;
|
||||
pub mod process2;
|
||||
pub mod pipe;
|
||||
pub mod process;
|
||||
pub mod rwlock;
|
||||
pub mod stack_overflow;
|
||||
pub mod sync;
|
||||
|
@ -59,16 +59,18 @@ impl Mutex {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ReentrantMutex { inner: Box<UnsafeCell<ffi::CRITICAL_SECTION>> }
|
||||
pub struct ReentrantMutex { inner: UnsafeCell<ffi::CRITICAL_SECTION> }
|
||||
|
||||
unsafe impl Send for ReentrantMutex {}
|
||||
unsafe impl Sync for ReentrantMutex {}
|
||||
|
||||
impl ReentrantMutex {
|
||||
pub unsafe fn new() -> ReentrantMutex {
|
||||
let mutex = ReentrantMutex { inner: box mem::uninitialized() };
|
||||
ffi::InitializeCriticalSection(mutex.inner.get());
|
||||
mutex
|
||||
pub unsafe fn uninitialized() -> ReentrantMutex {
|
||||
mem::uninitialized()
|
||||
}
|
||||
|
||||
pub unsafe fn init(&mut self) {
|
||||
ffi::InitializeCriticalSection(self.inner.get());
|
||||
}
|
||||
|
||||
pub unsafe fn lock(&self) {
|
||||
|
@ -26,9 +26,9 @@ use path::Path;
|
||||
use ptr;
|
||||
use sync::{StaticMutex, MUTEX_INIT};
|
||||
use sys::c;
|
||||
use sys::fs2::{OpenOptions, File};
|
||||
use sys::fs::{OpenOptions, File};
|
||||
use sys::handle::Handle;
|
||||
use sys::pipe2::AnonPipe;
|
||||
use sys::pipe::AnonPipe;
|
||||
use sys::stdio;
|
||||
use sys::{self, cvt};
|
||||
use sys_common::{AsInner, FromInner};
|
Loading…
x
Reference in New Issue
Block a user