Skip to content

Commit 0d3a41f

Browse files
committed
m: Cache thread-local ID access
Signed-off-by: John Nunley <[email protected]>
1 parent 3bba6b1 commit 0d3a41f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl<'a> Executor<'a> {
377377
.local_queues
378378
.read()
379379
.unwrap()
380-
.get(&thread::current().id())
380+
.get(&thread_id())
381381
.and_then(|list| list.first())
382382
{
383383
match local_queue.queue.push(runnable) {
@@ -1023,7 +1023,7 @@ impl Runner<'_> {
10231023
static ID_GENERATOR: AtomicUsize = AtomicUsize::new(0);
10241024
let runner_id = ID_GENERATOR.fetch_add(1, Ordering::SeqCst);
10251025

1026-
let origin_id = thread::current().id();
1026+
let origin_id = thread_id();
10271027
let runner = Runner {
10281028
state,
10291029
ticker: Ticker::for_runner(state, runner_id),
@@ -1225,6 +1225,15 @@ fn debug_executor(executor: &Executor<'_>, name: &str, f: &mut fmt::Formatter<'_
12251225
.finish()
12261226
}
12271227

1228+
fn thread_id() -> ThreadId {
1229+
thread_local! {
1230+
static ID: ThreadId = thread::current().id();
1231+
}
1232+
1233+
ID.try_with(|id| *id)
1234+
.unwrap_or_else(|_| thread::current().id())
1235+
}
1236+
12281237
/// Runs a closure when dropped.
12291238
struct CallOnDrop<F: FnMut()>(F);
12301239

0 commit comments

Comments
 (0)