Rollup merge of #123356 - joboet:set_current_size, r=ChrisDenton

Reduce code size of `thread::set_current`

#123265 introduced a rather large binary size regression, because it added an `unwrap()` call on a `Result<(), Thread>`, which in turn pulled its rather heavy `Debug` implementation. This PR fixes this by readding the `rtassert!` that was removed.
This commit is contained in:
Matthias Krüger 2024-05-04 12:37:20 +02:00 committed by GitHub
commit b8fa047398
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 2 deletions

View File

@ -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.