2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-04-25 17:56:49 +00:00

Merge pull request #747 from async-rs/fix/scheduler-perf

Fix new scheduler loop
This commit is contained in:
Yoshua Wuyts 2020-04-09 17:26:46 +02:00 committed by GitHub
commit aebba2bd95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -249,6 +249,8 @@ impl Machine {
continue; continue;
} }
let mut sched = rt.sched.lock().unwrap();
// One final check for available tasks while the scheduler is locked. // One final check for available tasks while the scheduler is locked.
if let Some(task) = iter::repeat_with(|| self.find_task(rt)) if let Some(task) = iter::repeat_with(|| self.find_task(rt))
.find(|s| !s.is_retry()) .find(|s| !s.is_retry())
@ -258,19 +260,19 @@ impl Machine {
continue; continue;
} }
let mut sched = rt.sched.lock().unwrap(); // If another thread is already blocked on the reactor, there is no point in keeping
// the current thread around since there is too little work to do.
if sched.polling { if sched.polling {
thread::sleep(Duration::from_micros(10)); break;
continue;
} }
// Unlock the schedule poll the reactor until new I/O events arrive.
sched.polling = true; sched.polling = true;
drop(sched); drop(sched);
rt.reactor.poll(None).unwrap(); rt.reactor.poll(None).unwrap();
let mut sched = rt.sched.lock().unwrap(); // Lock the scheduler again and re-register the machine.
sched = rt.sched.lock().unwrap();
sched.polling = false; sched.polling = false;
runs = 0; runs = 0;