diff options
| author | bors <bors@rust-lang.org> | 2024-05-04 12:41:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-05-04 12:41:40 +0000 |
| commit | d7ea27808deb5e10a0f7384e339e4e6165e33398 (patch) | |
| tree | ddd4cb3a7df1559199d877cad51f3626d13c75df /library/std/src/thread/mod.rs | |
| parent | 7dd170fccb3be6b1737af5df14dd736b366236c1 (diff) | |
| parent | 5f4f4fbb989b3f966b4fc1fd7bd3d5089c458cd2 (diff) | |
| download | rust-d7ea27808deb5e10a0f7384e339e4e6165e33398.tar.gz rust-d7ea27808deb5e10a0f7384e339e4e6165e33398.zip | |
Auto merge of #124703 - matthiaskrgr:rollup-2lljptd, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #123356 (Reduce code size of `thread::set_current`) - #124159 (Move thread parking to `sys::sync`) - #124293 (Let miri and const eval execute intrinsics' fallback bodies) - #124677 (Set non-leaf frame pointers on Fuchsia targets) - #124692 (We do not coerce `&mut &mut T -> *mut mut T`) - #124698 (Rewrite `rustdoc-determinism` test in Rust) - #124700 (Remove an unnecessary cast) - #124701 (Docs: suggest `uN::checked_sub` instead of check-then-unchecked) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/thread/mod.rs')
| -rw-r--r-- | library/std/src/thread/mod.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index 604eb05040b..78bc9af6c4d 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -174,8 +174,8 @@ use crate::ptr::addr_of_mut; use crate::str; use crate::sync::atomic::{AtomicUsize, Ordering}; use crate::sync::Arc; +use crate::sys::sync::Parker; use crate::sys::thread as imp; -use crate::sys_common::thread_parking::Parker; use crate::sys_common::{AsInner, IntoInner}; use crate::time::{Duration, Instant}; @@ -703,9 +703,14 @@ thread_local! { /// Sets the thread handle for the current thread. /// -/// Panics if the handle has been set already or when called from a TLS destructor. +/// Aborts if the handle has been set already to reduce code size. pub(crate) fn set_current(thread: Thread) { - CURRENT.with(|current| current.set(thread).unwrap()); + // Using `unwrap` here can add ~3kB to the binary size. We have complete + // control over where this is called, so just abort if there is a bug. + CURRENT.with(|current| match current.set(thread) { + Ok(()) => {} + Err(_) => rtabort!("thread::set_current should only be called once per thread"), + }); } /// Gets a handle to the thread that invokes it. |
