m: Cache thread-local ID access
Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
parent
3bba6b1b33
commit
0d3a41f930
13
src/lib.rs
13
src/lib.rs
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue