Cope with add-role after kill of a process

This commit is contained in:
Tony Garnock-Jones 2012-03-24 21:18:09 -04:00
parent ad8a31f703
commit e18b1f2a8c
1 changed files with 42 additions and 39 deletions

81
os2.rkt
View File

@ -251,45 +251,48 @@
[(kill pid-to-kill reason) (do-kill (or pid-to-kill pid) reason state)]))
(define (do-subscribe pid topic hs k state)
(define old-process (hash-ref (vm-processes state) pid))
(define eid-number (process-next-eid-number old-process))
(define new-eid (list pid eid-number))
(struct-copy vm (for*/fold ([state (run-trapk state pid k new-eid)])
([(matching-pid p) (in-hash (vm-processes state))]
[matching-eid (in-set (process-endpoints p))]
[e (in-value (hash-ref (vm-endpoints state) matching-eid))]
[matching-topic (in-value (endpoint-topic e))]
[flow-pattern (in-value (topic-intersection topic matching-topic))]
#:when flow-pattern)
(define inbound-flow (refine-topic matching-topic flow-pattern))
(define outbound-flow (refine-topic topic flow-pattern))
(let* ((state (if (flow-visible? topic inbound-flow)
(run-trapk state
pid
(handlers-presence hs)
new-eid
inbound-flow)
state))
(state (if (flow-visible? matching-topic outbound-flow)
(run-trapk state
matching-pid
(handlers-presence (endpoint-handlers e))
matching-eid
outbound-flow)
state)))
state))
[processes (hash-set (vm-processes state)
pid
(struct-copy process old-process
[next-eid-number (+ eid-number 1)]
[endpoints
(set-add (process-endpoints old-process)
new-eid)]))]
[endpoints (hash-set (vm-endpoints state)
new-eid
(endpoint new-eid
topic
hs))]))
(cond
[(hash-has-key? (vm-processes state) pid)
(define old-process (hash-ref (vm-processes state) pid))
(define eid-number (process-next-eid-number old-process))
(define new-eid (list pid eid-number))
(struct-copy vm (for*/fold ([state (run-trapk state pid k new-eid)])
([(matching-pid p) (in-hash (vm-processes state))]
[matching-eid (in-set (process-endpoints p))]
[e (in-value (hash-ref (vm-endpoints state) matching-eid))]
[matching-topic (in-value (endpoint-topic e))]
[flow-pattern (in-value (topic-intersection topic matching-topic))]
#:when flow-pattern)
(define inbound-flow (refine-topic matching-topic flow-pattern))
(define outbound-flow (refine-topic topic flow-pattern))
(let* ((state (if (flow-visible? topic inbound-flow)
(run-trapk state
pid
(handlers-presence hs)
new-eid
inbound-flow)
state))
(state (if (flow-visible? matching-topic outbound-flow)
(run-trapk state
matching-pid
(handlers-presence (endpoint-handlers e))
matching-eid
outbound-flow)
state)))
state))
[processes (hash-set (vm-processes state)
pid
(struct-copy process old-process
[next-eid-number (+ eid-number 1)]
[endpoints
(set-add (process-endpoints old-process)
new-eid)]))]
[endpoints (hash-set (vm-endpoints state)
new-eid
(endpoint new-eid
topic
hs))])]
[else state]))
(define (do-unsubscribe pid eid reason state)
(cond