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,22 +55,22 @@
(set! thread-swap-count 0)) (set! thread-swap-count 0))
(define (select-thread! [pending-callbacks null]) (define (select-thread! [pending-callbacks null])
(define callbacks (if (null? pending-callbacks)
(host:poll-async-callbacks)
pending-callbacks))
(host:poll-will-executors)
(poll-custodian-will-executor)
(check-external-events 'fast)
(call-pre-poll-external-callbacks)
(check-place-activity)
(check-queued-custodian-shutdown)
(when (and (null? callbacks)
(all-threads-poll-done?)
(waiting-on-external-or-idle?))
(or (check-external-events 'slow)
(try-post-idle)
(process-sleep)))
(let loop ([g root-thread-group] [pending-callbacks pending-callbacks] [none-k maybe-done]) (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))
(host:poll-will-executors)
(poll-custodian-will-executor)
(check-external-events 'fast)
(call-pre-poll-external-callbacks)
(check-place-activity)
(check-queued-custodian-shutdown)
(when (and (null? callbacks)
(all-threads-poll-done?)
(waiting-on-external-or-idle?))
(or (check-external-events 'slow)
(try-post-idle)
(process-sleep)))
(define child (thread-group-next! g)) (define child (thread-group-next! g))
(cond (cond
[(not child) (none-k callbacks)] [(not child) (none-k callbacks)]