work in progress: restartable task: fix become - use *self* for current task in ac-loop
This commit is contained in:
parent
8de0ee8927
commit
b8dd5314e2
2 changed files with 16 additions and 10 deletions
|
@ -47,12 +47,18 @@
|
|||
(defun stop (mb)
|
||||
(send mb +quit-message+))
|
||||
|
||||
(defvar *self* nil)
|
||||
|
||||
(defgeneric ac-loop (tsk bhv)
|
||||
(:method ((tsk async:mailbox) bhv)
|
||||
(let ((msg (async:rcv tsk)))
|
||||
(let ((*self* tsk)
|
||||
(msg (async:rcv tsk)))
|
||||
(unless (eq (content msg) +quit-message+)
|
||||
(ac-loop tsk (or (funcall bhv msg) bhv))))))
|
||||
|
||||
(defgeneric set-bhv (tsk bhv)
|
||||
(:method ((tsk async:mailbox) bhv)))
|
||||
|
||||
;;;; the core (classical, i.e. Hewitt) actor API
|
||||
|
||||
(defun create (bhv)
|
||||
|
@ -65,8 +71,9 @@
|
|||
;(util:lgi msg)
|
||||
(async:snd tsk msg)))
|
||||
|
||||
(defgeneric become (tsk bhv)
|
||||
(:method ((tsk async:mailbox) bhv) bhv))
|
||||
(defun become (bhv)
|
||||
(set-bhv *self* bhv)
|
||||
bhv)
|
||||
|
||||
;;;; handling restartable tasks
|
||||
|
||||
|
@ -76,9 +83,9 @@
|
|||
(if ok
|
||||
(if (eq (content msg) +quit-message+)
|
||||
(progn (async:set-status tsk :stopped) nil)
|
||||
(progn
|
||||
(let ((*self* tsk))
|
||||
(async:set-status tsk :running)
|
||||
(ac-vloop tsk (or (funcall bhv msg) bhv))))
|
||||
(ac-loop tsk (or (funcall bhv msg) bhv))))
|
||||
(progn (async:set-status tsk :suspended) bhv))))
|
||||
|
||||
(defmethod send ((tsk async:restartable-task) msg)
|
||||
|
@ -94,9 +101,8 @@
|
|||
tsk (lambda () (ac-loop tsk (async:behavior tsk)))))
|
||||
(async:set-status :running)))
|
||||
|
||||
(defmethod become ((tsk async:task) bhv)
|
||||
(setf (async:behavior tsk) bhv)
|
||||
bhv)
|
||||
(defmethod set-bhv ((tsk async:task) bhv)
|
||||
(setf (async:behavior tsk) bhv))
|
||||
|
||||
;;;; predefined behaviors
|
||||
|
||||
|
@ -114,7 +120,7 @@
|
|||
(lambda (msg)
|
||||
;(format t "calc ~a ~a~%" val (content msg))
|
||||
(destructuring-bind (fn &optional param) (content msg)
|
||||
(funcall fn msg val param))))
|
||||
(become (funcall fn msg val param)))))
|
||||
|
||||
(defun plus (msg val param)
|
||||
(calculator (+ val param)))
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
(:use :common-lisp)
|
||||
(:local-nicknames (:lp :lparallel)
|
||||
(:lpq :lparallel.queue))
|
||||
(:export #:init #:finish #:make-ch #:make-mb #:make-task #:rcv #:try-rcv #:snd
|
||||
(:export #:init #:finish #:make-mb #:make-task #:rcv #:try-rcv #:snd
|
||||
#:mailbox #:task #:restartable-task #:behavior #:get-status #:set-status
|
||||
#:submit-task #:receive-result #:try-receive-result))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue