Make ground async-channel always available, rather than dynamically

scoped to run-ground. This is important because (spawn-timer-driver),
for example, is called outside run-ground and spawns a thread that
communicates with ground via the ground async-channel. When we move to
running multiple grounds at once, we will have to revisit the
parameterization scheme here.
This commit is contained in:
Tony Garnock-Jones 2014-06-21 11:36:59 -04:00
parent ac6efba7a5
commit 90af8c3584
1 changed files with 33 additions and 36 deletions

View File

@ -21,14 +21,12 @@
;; (Parameterof (Option AsyncChannel))
;; Communication channel from auxiliary (usually driver) threads to
;; the currently-active ground VM.
(define current-ground-event-async-channel (make-parameter #f))
(define current-ground-event-async-channel (make-parameter (make-async-channel)))
;; Any -> Void
;; Sends a (non-feedback) message at the ground-VM metalevel.
(define (send-ground-message body)
(match (current-ground-event-async-channel)
[(? async-channel? ch) (async-channel-put ch (send body))]
[_ (error 'send-ground-message "Called outside dynamic scope of run-ground")]))
(async-channel-put (current-ground-event-async-channel) (send body)))
;; RacketEvent -> RacketEvent
;; Wraps a CML-style Racket event with a handler that sends the event
@ -61,7 +59,6 @@
;; Action* -> Void
;; Runs a ground VM, booting the outermost World with the given Actions.
(define (run-ground . boot-actions)
(parameterize ((current-ground-event-async-channel (make-async-channel)))
(let await-interrupt ((inert? #f) (p (spawn-world boot-actions)) (active-events '()))
(define active-gestalt (process-gestalt p))
(define event-list (if inert?
@ -92,4 +89,4 @@
(void)]
[_
(log-warning "run-ground: ignoring useless meta-action ~v" a)
(process-actions actions g)])]))]))))))
(process-actions actions g)])]))])))))