about summary refs log tree commit diff
path: root/src/libstd/thread/local.rs
AgeCommit message (Collapse)AuthorLines
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-6/+6
2019-03-25SGX target: fix std unit testsJethro Beekman-3/+3
2019-03-03race condition in thread local storage examplebenaryorg-1/+4
The example had a potential race condition that would still pass the test. If the thread which was supposed to modify it's own thread local was slower than the instruction to modify in the main thread, then the test would pass even in case of a failure. This is would be minor if the child thread was waited for since it check using an `assert_eq` for the same thing, but vice versa. However, if the `assert_eq` failed this would trigger a panic, which is not at all caught by the example since the thread is not waited on. Signed-off-by: benaryorg <binary@benary.org>
2019-03-02Bootstrap compiler update for 1.35 releaseMark Rousskov-6/+2
2019-02-28libstd => 2018Taiki Endo-23/+23
2019-02-11Require a list of features to allow in `allow_internal_unstable`Oliver Scherer-2/+6
2019-01-15OSX: fix #57534 registering thread dtors while running thread dtorstyler-7/+1
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-1/+1
2018-11-06Rollup merge of #55597 - alexcrichton:thread-local-inner, r=KodrAuskennytm-4/+4
std: Enable usage of `thread_local!` through imports The `thread_local!` macro delegated to an internal macro but it didn't do so in a macros-and-the-module-system compatible fashion, meaning if a `#![no_std]` crate imported `std` and tried to use `thread_local!` it would fail due to missing a lookup of an internal macro. This commit switches the macro to instead use `$crate` to invoke other macros, ensuring that it'll work when `thread_local!` is imported alone.
2018-11-01std: Enable usage of `thread_local!` through importsAlex Crichton-4/+4
The `thread_local!` macro delegated to an internal macro but it didn't do so in a macros-and-the-module-system compatible fashion, meaning if a `#![no_std]` crate imported `std` and tried to use `thread_local!` it would fail due to missing a lookup of an internal macro. This commit switches the macro to instead use `$crate` to invoke other macros, ensuring that it'll work when `thread_local!` is imported alone.
2018-11-01std: Improve codegen size of accessing TLSAlex Crichton-1/+10
Some code in the TLS implementation in libstd stores `Some(val)` into an `&mut Option<T>` (effectively) and then pulls out `&T`, but it currently uses `.unwrap()` which can codegen into a panic even though it can never panic. With sufficient optimizations enabled (like LTO) the compiler can see through this but this commit helps it along in normal mode (`--release` with Cargo by default) to avoid codegen'ing the panic path. This ends up improving the optimized codegen on wasm by ensuring that a call to panic pulling in more file size doesn't stick around.
2018-10-11std: Implement TLS for wasm32-unknown-unknownAlex Crichton-4/+10
This adds an implementation of thread local storage for the `wasm32-unknown-unknown` target when the `atomics` feature is implemented. This, however, comes with a notable caveat of that it requires a new feature of the standard library, `wasm-bindgen-threads`, to be enabled. Thread local storage for wasm (when `atomics` are enabled and there's actually more than one thread) is powered by the assumption that an external entity can fill in some information for us. It's not currently clear who will fill in this information nor whose responsibility it should be long-term. In the meantime there's a strategy being gamed out in the `wasm-bindgen` project specifically, and the hope is that we can continue to test and iterate on the standard library without committing to a particular strategy yet. As to the details of `wasm-bindgen`'s strategy, LLVM doesn't currently have the ability to emit custom `global` values (thread locals in a `WebAssembly.Module`) so we leverage the `wasm-bindgen` CLI tool to do it for us. To that end we have a few intrinsics, assuming two global values: * `__wbindgen_current_id` - gets the current thread id as a 32-bit integer. It's `wasm-bindgen`'s responsibility to initialize this per-thread and then inform libstd of the id. Currently `wasm-bindgen` performs this initialization as part of the `start` function. * `__wbindgen_tcb_{get,set}` - in addition to a thread id it's assumed that there's a global available for simply storing a pointer's worth of information (a thread control block, which currently only contains thread local storage). This would ideally be a native `global` injected by LLVM, but we don't have a great way to support that right now. To reiterate, this is all intended to be unstable and purely intended for testing out Rust on the web with threads. The story is very likely to change in the future and we want to make sure that we're able to do that!
2018-06-27Fix the error reference for LocalKey::try_withMichal 'vorner' Vaner-1/+1
2018-04-13std: Minimize size of panicking on wasmAlex Crichton-2/+39
This commit applies a few code size optimizations for the wasm target to the standard library, namely around panics. We notably know that in most configurations it's impossible for us to print anything in wasm32-unknown-unknown so we can skip larger portions of panicking that are otherwise simply informative. This allows us to get quite a nice size reduction. Finally we can also tweak where the allocation happens for the `Box<Any>` that we panic with. By only allocating once unwinding starts we can reduce the size of a panicking wasm module from 44k to 350 bytes.
2018-03-01Fix a bug introduced in previous commitStjepan Glavina-6/+3
2018-02-28Remove thread_local_stateStjepan Glavina-104/+7
2018-02-28Stabilize LocalKey::try_withStjepan Glavina-13/+15
2017-10-26Bump to 1.23 and update bootstrapAlex Crichton-5/+0
This commit updates the bootstrap compiler, bumps the version to 1.23, updates Cargo, updates books, and updates crates.io dependencies
2017-10-17Docs: a LocalKey might start in the Valid stateStjepan Glavina-1/+4
2017-09-07std::thread::LocalKey: Document limitation with initializersJoshua Liebow-Feeser-0/+4
2017-09-04Make the LocalKey facade of thread_local! inlineable cross-crate.Eduard-Mihai Burtescu-3/+13
2017-08-31Update bootstrap compilerAlex Crichton-4/+1
This commit updates the bootstrap compiler and clears out a number of #[cfg(stage0)] annotations and related business
2017-08-15use field init shorthand EVERYWHEREZack M. Davis-2/+2
Like #43008 (f668999), but _much more aggressive_.
2017-08-12Check #[thread_local] statics correctly in the compiler.Eduard-Mihai Burtescu-31/+31
2017-07-25Bump master to 1.21.0Alex Crichton-67/+0
This commit bumps the master branch's version to 1.21.0 and also updates the bootstrap compiler from the freshly minted beta release.
2017-07-15Auto merge of #43185 - durka:thread-local-pub-restricted, r=alexcrichtonbors-1/+57
support pub(restricted) in thread_local! (round 2) Resurrected #40984 now that the issue blocking it was fixed. Original description: `pub(restricted)` was stabilized in #40556 so let's go! Here is a [playground](https://play.rust-lang.org/?gist=f55f32f164a6ed18c219fec8f8293b98&version=nightly&backtrace=1). I changed the interface of `__thread_local_inner!`, which is supposedly unstable but this is not checked for macros (#34097 cc @petrochenkov @jseyfried), so this may be an issue.
2017-07-12Use try_with for with implementationLee Bousfield-9/+2
2017-07-11stage0 fallbackAlex Burka-0/+67
2017-07-11use :vis in thread_local!Alex Burka-30/+8
2017-07-11support pub(restricted) in thread_local!Alex Burka-32/+43
2017-07-10Add LocalKey::try_with as an alternative to stateLee Bousfield-0/+52
2017-06-23rustc: Enable #[thread_local] for WindowsAlex Crichton-3/+79
I think LLVM has had support for quite some time now for this, we just never got around to testing it out and binding it. We've had some trouble landing this in the past I believe, but it's time to try again! This commit flags the `#[thread_local]` attribute as being available for Windows targets and adds an implementation of `register_dtor` in the `thread::local` module to ensure we can destroy these keys. The same functionality is implemented in clang via a function called `__tlregdtor` (presumably provided in some Windows runtime somewhere), but this function unfortunately does not take a data pointer (just a thunk) which means we can't easily call it. For now destructors are just run in the same way the Linux fallback is implemented, which is just keeping track via a single OS-based TLS key.
2017-05-15Add links to the `thread::LocalKey` doc.Felix Raimundo-15/+30
Part of #29378 .
2017-03-12Update usages of 'OSX' (and other old names) to 'macOS'.Corey Farwell-3/+3
As of last year with version 'Sierra', the Mac operating system is now called 'macOS'.
2017-02-15Fix wording in LocalKey documentationStjepan Glavina-2/+2
2017-01-29Fix a few impl stability attributesOliver Middleton-2/+1
The versions show up in rustdoc.
2016-12-18Implement `fmt::Debug` for all structures in libstd.Corey Farwell-1/+17
Part of https://github.com/rust-lang/rust/issues/31869. Also turn on the `missing_debug_implementations` lint at the crate level.
2016-11-01std: Move elf TLS to sys::fast_thread_localBrian Anderson-161/+2
2016-10-22Add Fuchsia supportRaph Levien-30/+42
Adds support for the x86_64-unknown-fuchsia target, which covers the Fuchsia operating system.
2016-09-30Ignore various entire test modules on emscriptenBrian Anderson-7/+1
2016-09-30Ignore lots and lots of std tests on emscriptenBrian Anderson-0/+6
2016-08-24Use `#[prelude_import]` in `libstd`.Jeffrey Seyfried-7/+0
2016-06-22upgrade thread_local! invocation syntaxAlex Burka-4/+38
Allows declaring multiple statics in one macro invocation, and supports attaching attributes to the generated items.
2016-04-25libstd: fix typos in thread::LocalKey docsRyman-2/+2
2016-02-04Stop using unsafe code in TLS macro expansion (fixes #30756)Manish Goregaokar-23/+27
2016-01-29std: Ignore dtors_in_dtors_in_dtors on OSXAlex Crichton-0/+25
This test has been deadlocking and causing problems on the bots basically since its inception. Some memory safety issues were fixed in 987dc84b, but the deadlocks remained afterwards unfortunately. After some investigation, I've concluded that this is just a situation where OSX is not guaranteed to run destructors. The fix in 987dc84b observed that OSX was rewriting the backing TLS memory to its initial state during destruction while we weren't looking, and this would have the effect of canceling the destructors of any other initialized TLS slots. While very difficult to pin down, this is basically what I assume is happening here, so there doesn't seem to really be anythig we can do to ensure the test robustly passes on OSX, so just ignore it for now.
2015-12-21std: Use cfg(target_thread_local) in thread_local!Alex Crichton-76/+44
This transitions the standard library's `thread_local!` macro to use the freshly-added and gated `#[cfg(target_thread_local)]` attribute. This greatly simplifies the `#[cfg]` logic in play here, but requires that the standard library expose both the OS and ELF TLS implementation modules as unstable implementation details. The implementation details were shuffled around a bit but end up generally compiling to the same thing. Closes #26581 (this supersedes the need for the option) Closes #27057 (this also starts ignoring the option)
2015-12-08std: Use mem::replace in TLS initializationAlex Crichton-1/+16
Due to #30228 it's not currently sound to do `*ptr = Some(value)`, so instead use `mem::replace` which fixes the soundness hole for now.
2015-10-30don't use drop_in_place as an intrinsicAlexis Beingessner-1/+1