cs & thread: avoid accumulating post-atomic callbacks

Only one instance of each callback is needed. Allowing them to pile up
is inefficient, and possibly it can trigger a reaction that causes
even more to pile up.
This commit is contained in:
Matthew Flatt 2019-09-18 14:00:54 -06:00
parent b86ca89102
commit ec72f5df45

View File

@ -105,7 +105,14 @@
;; no race with the scheduler ;; no race with the scheduler
(define (add-end-atomic-callback! cb) (define (add-end-atomic-callback! cb)
(host:disable-interrupts) (host:disable-interrupts)
(end-atomic-callback (cons cb (end-atomic-callback))) (define all-cbs (end-atomic-callback))
(let loop ([cbs all-cbs])
(cond
[(eq? cbs 0)
(end-atomic-callback (cons cb all-cbs))]
[else
(unless (eq? (car cbs) cb)
(loop (cdr cbs)))]))
(host:enable-interrupts)) (host:enable-interrupts))
;; ---------------------------------------- ;; ----------------------------------------