diff options
| author | bors <bors@rust-lang.org> | 2017-05-25 01:51:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-05-25 01:51:35 +0000 |
| commit | cf747fcbf716a8afced9d23aa15bb47d93805209 (patch) | |
| tree | a2215e4dd219883e96acebbdcc24257c99d79133 /src/libstd | |
| parent | 5b13bff5203c1bdc6ac6dc87f69b5359a9503078 (diff) | |
| parent | d429b495a4bfba26d2c18fd9e140e17a787538d8 (diff) | |
| download | rust-cf747fcbf716a8afced9d23aa15bb47d93805209.tar.gz rust-cf747fcbf716a8afced9d23aa15bb47d93805209.zip | |
Auto merge of #42212 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 15 pull requests - Successful merges: #41980, #42071, #42120, #42134, #42141, #42142, #42149, #42150, #42159, #42177, #42186, #42191, #42195, #42198, #42211 - Failed merges:
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ffi/os_str.rs | 12 | ||||
| -rw-r--r-- | src/libstd/rt.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/mpsc_queue.rs | 35 | ||||
| -rw-r--r-- | src/libstd/sync/mpsc/spsc_queue.rs | 39 | ||||
| -rw-r--r-- | src/libstd/sys/redox/thread_local.rs | 5 | ||||
| -rw-r--r-- | src/libstd/thread/mod.rs | 25 |
6 files changed, 64 insertions, 57 deletions
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index f497734e249..a5a1b5e5f09 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -247,7 +247,9 @@ impl OsString { self.inner.shrink_to_fit() } - /// Converts this `OsString` into a boxed `OsStr`. + /// Converts this `OsString` into a boxed [`OsStr`]. + /// + /// [`OsStr`]: struct.OsStr.html /// /// # Examples /// @@ -482,12 +484,13 @@ impl OsStr { /// Returns the length of this `OsStr`. /// /// Note that this does **not** return the number of bytes in this string - /// as, for example, OS strings on Windows are encoded as a list of `u16` + /// as, for example, OS strings on Windows are encoded as a list of [`u16`] /// rather than a list of bytes. This number is simply useful for passing to /// other methods like [`OsString::with_capacity`] to avoid reallocations. /// /// See `OsStr` introduction for more information about encoding. /// + /// [`u16`]: ../primitive.u16.html /// [`OsString::with_capacity`]: struct.OsString.html#method.with_capacity /// /// # Examples @@ -506,7 +509,10 @@ impl OsStr { self.inner.inner.len() } - /// Converts a `Box<OsStr>` into an `OsString` without copying or allocating. + /// Converts a [`Box`]`<OsStr>` into an [`OsString`] without copying or allocating. + /// + /// [`Box`]: ../boxed/struct.Box.html + /// [`OsString`]: struct.OsString.html #[unstable(feature = "into_boxed_os_str", issue = "40380")] pub fn into_os_string(self: Box<OsStr>) -> OsString { let inner: Box<Slice> = unsafe { mem::transmute(self) }; diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index acff7faf8a7..06fd838ea06 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -35,6 +35,8 @@ fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize { use sys_common; use sys_common::thread_info; use thread::Thread; + #[cfg(not(feature = "backtrace"))] + use mem; sys::init(); @@ -53,9 +55,12 @@ fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize { sys::args::init(argc, argv); // Let's run some code! + #[cfg(feature = "backtrace")] let res = panic::catch_unwind(|| { ::sys_common::backtrace::__rust_begin_short_backtrace(main) }); + #[cfg(not(feature = "backtrace"))] + let res = panic::catch_unwind(mem::transmute::<_, fn()>(main)); sys_common::cleanup(); res.is_err() }; diff --git a/src/libstd/sync/mpsc/mpsc_queue.rs b/src/libstd/sync/mpsc/mpsc_queue.rs index 8d80f942ff7..296773d20f6 100644 --- a/src/libstd/sync/mpsc/mpsc_queue.rs +++ b/src/libstd/sync/mpsc/mpsc_queue.rs @@ -1,29 +1,12 @@ -/* Copyright (c) 2010-2011 Dmitry Vyukov. All rights reserved. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY DMITRY VYUKOV "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL DMITRY VYUKOV OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are - * those of the authors and should not be interpreted as representing official - * policies, either expressed or implied, of Dmitry Vyukov. - */ +// Copyright 2017 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. //! A mostly lock-free multi-producer, single consumer queue. //! diff --git a/src/libstd/sync/mpsc/spsc_queue.rs b/src/libstd/sync/mpsc/spsc_queue.rs index 5858e4b6ddb..1148bc66fba 100644 --- a/src/libstd/sync/mpsc/spsc_queue.rs +++ b/src/libstd/sync/mpsc/spsc_queue.rs @@ -1,31 +1,12 @@ -/* Copyright (c) 2010-2011 Dmitry Vyukov. All rights reserved. - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY DMITRY VYUKOV "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL DMITRY VYUKOV OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are - * those of the authors and should not be interpreted as representing official - * policies, either expressed or implied, of Dmitry Vyukov. - */ - -// http://www.1024cores.net/home/lock-free-algorithms/queues/unbounded-spsc-queue +// Copyright 2017 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. //! A single-producer single-consumer concurrent queue //! @@ -33,6 +14,8 @@ //! concurrently between two threads. This data structure is safe to use and //! enforces the semantics that there is one pusher and one popper. +// http://www.1024cores.net/home/lock-free-algorithms/queues/unbounded-spsc-queue + use alloc::boxed::Box; use core::ptr; use core::cell::UnsafeCell; diff --git a/src/libstd/sys/redox/thread_local.rs b/src/libstd/sys/redox/thread_local.rs index abdd9ace795..cacd84e2102 100644 --- a/src/libstd/sys/redox/thread_local.rs +++ b/src/libstd/sys/redox/thread_local.rs @@ -64,3 +64,8 @@ pub unsafe fn set(key: Key, value: *mut u8) { pub unsafe fn destroy(key: Key) { keys().remove(&key); } + +#[inline] +pub fn requires_synchronized_create() -> bool { + false +} diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 154406a1d8b..d0e3b00d75f 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -359,9 +359,12 @@ impl Builder { } unsafe { thread_info::set(imp::guard::current(), their_thread); + #[cfg(feature = "backtrace")] let try_result = panic::catch_unwind(panic::AssertUnwindSafe(|| { ::sys_common::backtrace::__rust_begin_short_backtrace(f) })); + #[cfg(not(feature = "backtrace"))] + let try_result = panic::catch_unwind(panic::AssertUnwindSafe(f)); *their_packet.get() = Some(try_result); } }; @@ -394,6 +397,26 @@ impl Builder { /// want to specify the stack size or the name of the thread, use this API /// instead. /// +/// As you can see in the signature of `spawn` there are two constraints on +/// both the closure given to `spawn` and its return value, let's explain them: +/// +/// - The `'static` constraint means that the closure and its return value +/// must have a lifetime of the whole program execution. The reason for this +/// is that threads can `detach` and outlive the lifetime they have been +/// created in. +/// Indeed if the thread, and by extension its return value, can outlive their +/// caller, we need to make sure that they will be valid afterwards, and since +/// we *can't* know when it will return we need to have them valid as long as +/// possible, that is until the end of the program, hence the `'static` +/// lifetime. +/// - The [`Send`] constraint is because the closure will need to be passed +/// *by value* from the thread where it is spawned to the new thread. Its +/// return value will need to be passed from the new thread to the thread +/// where it is `join`ed. +/// As a reminder, the [`Send`] marker trait, expresses that it is safe to be +/// passed from thread to thread. [`Sync`] expresses that it is safe to have a +/// reference be passed from thread to thread. +/// /// # Panics /// /// Panics if the OS fails to create a thread; use [`Builder::spawn`] @@ -460,6 +483,8 @@ impl Builder { /// [`panic`]: ../../std/macro.panic.html /// [`Builder::spawn`]: ../../std/thread/struct.Builder.html#method.spawn /// [`Builder`]: ../../std/thread/struct.Builder.html +/// [`Send`]: ../../std/marker/trait.Send.html +/// [`Sync`]: ../../std/marker/trait.Sync.html #[stable(feature = "rust1", since = "1.0.0")] pub fn spawn<F, T>(f: F) -> JoinHandle<T> where F: FnOnce() -> T, F: Send + 'static, T: Send + 'static |
