2014-08-06 19:16:50 +00:00
|
|
|
#lang racket/base
|
2013-03-29 03:00:29 +00:00
|
|
|
|
|
|
|
(require racket/match)
|
2014-08-06 19:16:50 +00:00
|
|
|
(require "structs.rkt")
|
2013-03-29 03:00:29 +00:00
|
|
|
(require "roles.rkt")
|
|
|
|
(require "vm.rkt")
|
2014-08-06 19:16:50 +00:00
|
|
|
(require "log.rkt")
|
2013-03-29 03:00:29 +00:00
|
|
|
(require "process.rkt")
|
|
|
|
(require "action-delete-endpoint.rkt")
|
2014-08-06 19:16:50 +00:00
|
|
|
(require "quasiqueue.rkt")
|
2013-03-29 03:00:29 +00:00
|
|
|
|
|
|
|
(provide do-quit)
|
|
|
|
|
2014-08-06 19:16:50 +00:00
|
|
|
;; do-quit : (All (State) PID Reason (process State) vm
|
|
|
|
;; -> (values (Option (process State)) vm (QuasiQueue (Action vm))))
|
2013-03-29 03:00:29 +00:00
|
|
|
(define (do-quit killed-pid reason p state)
|
|
|
|
|
2014-08-06 19:16:50 +00:00
|
|
|
;; log-quit : (All (KilledState) (process KilledState) -> Void)
|
2013-03-29 03:00:29 +00:00
|
|
|
(define (log-quit p)
|
2013-05-30 21:54:53 +00:00
|
|
|
(marketplace-log (if reason 'warning 'info)
|
|
|
|
"PID ~v (~a) quits with reason: ~a"
|
|
|
|
killed-pid
|
|
|
|
(process-debug-name p)
|
|
|
|
(if (exn? reason)
|
2015-05-23 15:45:15 +00:00
|
|
|
(parameterize ([current-error-port (open-output-string)])
|
|
|
|
((error-display-handler) (exn-message reason) reason)
|
|
|
|
(get-output-string (current-error-port)))
|
2013-05-30 21:54:53 +00:00
|
|
|
(format "~v" reason))))
|
2013-03-29 03:00:29 +00:00
|
|
|
|
|
|
|
(if (equal? killed-pid (process-pid p))
|
|
|
|
(let-values (((p state meta-actions) (delete-all-endpoints reason p state)))
|
|
|
|
(log-quit p)
|
|
|
|
(values #f state meta-actions))
|
|
|
|
(let-values (((state maybe-killed-wp) (extract-process state killed-pid)))
|
|
|
|
(if (not maybe-killed-wp)
|
|
|
|
(values p state (empty-quasiqueue))
|
|
|
|
(apply values
|
2014-08-06 19:16:50 +00:00
|
|
|
(let ((killed-p maybe-killed-wp))
|
2013-03-29 03:00:29 +00:00
|
|
|
(log-quit killed-p)
|
|
|
|
(let-values (((killed-p state meta-actions)
|
|
|
|
(delete-all-endpoints reason killed-p state)))
|
|
|
|
(list p state meta-actions))))))))
|