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