thread: avoid repeated polls while scanning available threads

Poll for external events just once before starting a search for an
available thread, instead of polling every iteration in the search.
This commit is contained in:
Matthew Flatt 2019-06-17 09:40:54 -06:00
parent 6d200e6143
commit 97e61b5f25

View File

@ -55,7 +55,6 @@
(set! thread-swap-count 0))
(define (select-thread! [pending-callbacks null])
(let loop ([g root-thread-group] [pending-callbacks pending-callbacks] [none-k maybe-done])
(define callbacks (if (null? pending-callbacks)
(host:poll-async-callbacks)
pending-callbacks))
@ -71,6 +70,7 @@
(or (check-external-events 'slow)
(try-post-idle)
(process-sleep)))
(let loop ([g root-thread-group] [pending-callbacks pending-callbacks] [none-k maybe-done])
(define child (thread-group-next! g))
(cond
[(not child) (none-k callbacks)]