Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed Oct 11, 2023
1 parent b4c79a1 commit 3fbd53d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
19 changes: 11 additions & 8 deletions async.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,28 @@
(make-instance 'promise-task :promise (promise:make) :func function)
main))

(defclass task-runner-main (main)
(defclass task-runner ()
((task-thread :initform (make-instance 'task-thread) :accessor task-thread)))

(defmethod initialize-instance ((main task-runner-main) &key)
(defmethod initialize-instance ((runner task-runner) &key)
(call-next-method)
(start (task-thread main)))
(start (task-thread runner)))

(defmethod finalize :after ((main task-runner-main))
(stop (task-thread main)))
(defmethod finalize :after ((runner task-runner))
(stop (task-thread runner)))

(defmethod simple-tasks:schedule-task (task (runner task-runner))
(simple-tasks:schedule-task task (task-thread runner)))

(defclass task-runner-main (task-runner main)
())

(defmethod update :before ((main task-runner-main) tt dt fc)
(promise:tick-all dt))

(defmethod simple-tasks:schedule-task (task (default (eql T)))
(simple-tasks:schedule-task task +main+))

(defmethod simple-tasks:schedule-task (task (main task-runner-main))
(simple-tasks:schedule-task task (task-thread +main+)))

(defclass promise-task (simple-tasks:task)
((promise :initarg :promise :accessor promise :reader promise:ensure-promise)
(func :initarg :func :accessor func)))
Expand Down
10 changes: 10 additions & 0 deletions context.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
(height 0 :type (unsigned-byte 16))
(data #() :type (simple-array (unsigned-byte 8))))

(defgeneric create-child-context (context))
(defgeneric create-context (context))
(defgeneric destroy-context (context))
(defgeneric valid-p (context))
Expand Down Expand Up @@ -115,6 +116,15 @@
(destroy-context context)
(call-next-method))

(defmethod create-child-context ((context context))
(let ((restore (current-p context))
(child (make-instance 'context :share-with context)))
(create-context child)
(when restore
(done-current child)
(make-current context))
child))

(defmethod destroy-context :around ((context context))
(when (valid-p context)
(with-context (context :force T)
Expand Down
1 change: 1 addition & 0 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@
#:rgba-icon-width
#:rgba-icon-height
#:rgba-icon-data
#:create-child-context
#:create-context
#:destroy-context
#:valid-p
Expand Down

0 comments on commit 3fbd53d

Please sign in to comment.