Skip to content

Commit a80088e

Browse files
committed
m: Cache thread-local ID access
Signed-off-by: John Nunley <[email protected]>
1 parent 871c642 commit a80088e

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
@@ -355,7 +355,7 @@ impl<'a> Executor<'a> {
355355
.local_queues
356356
.read()
357357
.unwrap()
358-
.get(&thread::current().id())
358+
.get(&thread_id())
359359
.and_then(|list| list.first())
360360
{
361361
match local_queue.queue.push(runnable) {
@@ -1040,7 +1040,7 @@ impl Runner<'_> {
10401040
static ID_GENERATOR: AtomicUsize = AtomicUsize::new(0);
10411041
let runner_id = ID_GENERATOR.fetch_add(1, Ordering::SeqCst);
10421042

1043-
let origin_id = thread::current().id();
1043+
let origin_id = thread_id();
10441044
let runner = Runner {
10451045
state,
10461046
ticker: Ticker::for_runner(state, runner_id),
@@ -1247,6 +1247,15 @@ fn debug_state(state: &State, name: &str, f: &mut fmt::Formatter<'_>) -> fmt::Re
12471247
.finish()
12481248
}
12491249

1250+
fn thread_id() -> ThreadId {
1251+
thread_local! {
1252+
static ID: ThreadId = thread::current().id();
1253+
}
1254+
1255+
ID.try_with(|id| *id)
1256+
.unwrap_or_else(|_| thread::current().id())
1257+
}
1258+
12501259
/// Runs a closure when dropped.
12511260
struct CallOnDrop<F: FnMut()>(F);
12521261

0 commit comments

Comments
 (0)