m: Cache thread-local ID access

Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
John Nunley 2024-04-24 20:19:09 -07:00
parent 3bba6b1b33
commit 0d3a41f930
No known key found for this signature in database
GPG Key ID: 2FE69973CFD64832
1 changed files with 11 additions and 2 deletions

View File

@ -377,7 +377,7 @@ impl<'a> Executor<'a> {
.local_queues
.read()
.unwrap()
.get(&thread::current().id())
.get(&thread_id())
.and_then(|list| list.first())
{
match local_queue.queue.push(runnable) {
@ -1023,7 +1023,7 @@ impl Runner<'_> {
static ID_GENERATOR: AtomicUsize = AtomicUsize::new(0);
let runner_id = ID_GENERATOR.fetch_add(1, Ordering::SeqCst);
let origin_id = thread::current().id();
let origin_id = thread_id();
let runner = Runner {
state,
ticker: Ticker::for_runner(state, runner_id),
@ -1225,6 +1225,15 @@ fn debug_executor(executor: &Executor<'_>, name: &str, f: &mut fmt::Formatter<'_
.finish()
}
fn thread_id() -> ThreadId {
thread_local! {
static ID: ThreadId = thread::current().id();
}
ID.try_with(|id| *id)
.unwrap_or_else(|_| thread::current().id())
}
/// Runs a closure when dropped.
struct CallOnDrop<F: FnMut()>(F);