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)
(define lookup (unbox lookup-box))
(when lookup
(rktio_addrinfo_lookup_stop lookup)))
(rktio_addrinfo_lookup_stop rktio lookup)))
;; in atomic mode
(lambda (lookup-box)
(define lookup (unbox lookup-box))

View File

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

View File

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

View File

@ -61,6 +61,9 @@
((sandman-do-remove-thread! the-sandman) th h))
;; 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)
((sandman-do-poll the-sandman) mode thread-wakeup))

View File

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