cs & io: fix fd semaphore polling

Reducing external-event polling exposed a problem with fd semaphore
checking, where the check before sleeping didn't abandon the sleep if
an fd semaphore was posted.

Also, fix a bug with interrupted network address lookup.
This commit is contained in:
Matthew Flatt 2019-06-19 18:12:21 -06:00
parent 1ba4d76fe0
commit 2a1404f9a3
5 changed files with 13 additions and 8 deletions

View File

@ -34,7 +34,7 @@
(lambda (lookup-box) (lambda (lookup-box)
(define lookup (unbox lookup-box)) (define lookup (unbox lookup-box))
(when lookup (when lookup
(rktio_addrinfo_lookup_stop lookup))) (rktio_addrinfo_lookup_stop rktio lookup)))
;; in atomic mode ;; in atomic mode
(lambda (lookup-box) (lambda (lookup-box)
(define lookup (unbox lookup-box)) (define lookup (unbox lookup-box))

View File

@ -8,7 +8,7 @@
shared-ltps-place-init! shared-ltps-place-init!
fd-semaphore-update! fd-semaphore-update!
fd-semaphore-poll-ready) fd-semaphore-poll-ready?)
(define (make-ltps) (define (make-ltps)
(define ltps (rktio_ltps_open rktio)) (define ltps (rktio_ltps_open rktio))
@ -63,18 +63,18 @@
s])])])) s])])]))
;; in atomic mode ;; in atomic mode
(define (fd-semaphore-poll-ready) (define (fd-semaphore-poll-ready?)
(unless (eq? shared-ltps rktio_NULL) (unless (eq? shared-ltps rktio_NULL)
(rktio_ltps_poll rktio shared-ltps) (rktio_ltps_poll rktio shared-ltps)
(let loop () (let loop ([did? #f])
(define h (rktio_ltps_get_signaled_handle rktio shared-ltps)) (define h (rktio_ltps_get_signaled_handle rktio shared-ltps))
(cond (cond
[(rktio-error? h) [(rktio-error? h)
;; Could log an error that isn't RKTIO_ERROR_LTPS_NOT_FOUND ;; Could log an error that isn't RKTIO_ERROR_LTPS_NOT_FOUND
(void)] did?]
[else [else
(define ib (address->immobile-cell (rktio_ltps_handle_get_data rktio h))) (define ib (address->immobile-cell (rktio_ltps_handle_get_data rktio h)))
(semaphore-post-all (immobile-cell-ref ib)) (semaphore-post-all (immobile-cell-ref ib))
(free-immobile-cell ib) (free-immobile-cell ib)
(rktio_free h) (rktio_free h)
(loop)])))) (loop #t)]))))

View File

@ -97,7 +97,8 @@
[(eqv? v RKTIO_OS_SIGNAL_TERM) 'terminate] [(eqv? v RKTIO_OS_SIGNAL_TERM) 'terminate]
[else 'break])) [else 'break]))
(check-signals))) (check-signals)))
(fd-semaphore-poll-ready) (when (fd-semaphore-poll-ready?)
(wakeup #f))
((sandman-do-poll timeout-sandman) mode wakeup)) ((sandman-do-poll timeout-sandman) mode wakeup))
;; get-wakeup ;; get-wakeup

View File

@ -61,6 +61,9 @@
((sandman-do-remove-thread! the-sandman) th h)) ((sandman-do-remove-thread! the-sandman) th h))
;; in atomic mode ;; in atomic mode
;; The `thread-wakeup` callback can be called with #f
;; to indicate that a thread was potentially woken up
;; some other way, such as by a semaphore post
(define (sandman-poll mode thread-wakeup) (define (sandman-poll mode thread-wakeup)
((sandman-do-poll the-sandman) mode thread-wakeup)) ((sandman-do-poll the-sandman) mode thread-wakeup))

View File

@ -174,7 +174,8 @@
(define did? #f) (define did? #f)
(sandman-poll mode (sandman-poll mode
(lambda (t) (lambda (t)
(thread-reschedule! t) (when t
(thread-reschedule! t))
(set! did? #t))) (set! did? #t)))
(when did? (when did?
(thread-did-work!)) (thread-did-work!))