Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Remove unnecessary std::thread_local
  • Loading branch information
tidely committed Oct 29, 2025
commit aadaf23a45860fc91402896db644724f4e460c2d
15 changes: 3 additions & 12 deletions src/runnable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,6 @@ impl<M> Builder<M> {
use std::task::{Context, Poll};
use std::thread::{self, ThreadId};

#[inline]
fn thread_id() -> ThreadId {
std::thread_local! {
static ID: ThreadId = thread::current().id();
}
ID.try_with(|id| *id)
.unwrap_or_else(|_| thread::current().id())
}

struct Checked<F> {
id: ThreadId,
inner: ManuallyDrop<F>,
Expand All @@ -454,7 +445,7 @@ impl<M> Builder<M> {
impl<F> Drop for Checked<F> {
fn drop(&mut self) {
assert!(
self.id == thread_id(),
self.id == thread::current().id(),
"local task dropped by a thread that didn't spawn it"
);
unsafe {
Expand All @@ -468,7 +459,7 @@ impl<M> Builder<M> {

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
assert!(
self.id == thread_id(),
self.id == thread::current().id(),
"local task polled by a thread that didn't spawn it"
);
unsafe { self.map_unchecked_mut(|c| &mut *c.inner).poll(cx) }
Expand All @@ -480,7 +471,7 @@ impl<M> Builder<M> {
let future = future(meta);

Checked {
id: thread_id(),
id: thread::current().id(),
inner: ManuallyDrop::new(future),
}
};
Expand Down