Add macros to simplify async evaluation
This commit is contained in:
parent
7e9ed2c1ac
commit
383e156c91
3 changed files with 25 additions and 3 deletions
|
|
@ -41,4 +41,5 @@
|
|||
(if sync
|
||||
(with-promise (resolve reject)
|
||||
(resolve (do-load-file filepath type)))
|
||||
(push-new-job #'do-load-file (list filepath type))))
|
||||
(async-job (filepath type)
|
||||
(do-load-file filepath type))))
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
(:export #:job #:job-fun #:job-args #:job-callback
|
||||
#:job-thread #:thread-terminate-p
|
||||
#:specialized-thread #:job-queue
|
||||
#:push-new-job #:push-new-thread
|
||||
#:async-job #:eval-on-thread #:push-new-thread
|
||||
#:push-new-job-thread #:push-new-specialized-thread
|
||||
#:get-next-job #:job-run
|
||||
#:terminate-thread
|
||||
|
|
@ -79,6 +79,23 @@
|
|||
(condition-notify *job-waitqueue*))
|
||||
(job-run job *current-thread-object*)))))
|
||||
|
||||
(defmacro async-job (args &body body)
|
||||
(if args
|
||||
`(push-new-job (lambda ,args ,@body) (list ,@args))
|
||||
`(push-new-job (lambda () ,@body))))
|
||||
|
||||
(defun push-job-to-thread (thread fun &optional args)
|
||||
(with-promise (resolve reject :resolve-fn resolver :reject-fn rejecter)
|
||||
(let ((job (make-job (make-job-id) fun args resolver rejecter)))
|
||||
(if thread
|
||||
(enqueue (job-queue thread) job)
|
||||
(error "Thread ~a is not available~%" thread)))))
|
||||
|
||||
(defmacro eval-on-thread (args thread &body body)
|
||||
(if args
|
||||
`(push-job-to-thread ,thread (lambda ,args ,@body) (list ,@args))
|
||||
`(push-job-to-thread ,thread (lambda () ,@body))))
|
||||
|
||||
(defun make-base-thread (type name fun)
|
||||
"Create a new thread."
|
||||
(let* ((id (make-thread-id))
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@
|
|||
:stoe/engine/gl-utils
|
||||
:stoe/engine/mesh
|
||||
:stoe/engine/viewport
|
||||
:stoe/engine/scene))
|
||||
:stoe/engine/scene)
|
||||
(:export #:on-render-thread))
|
||||
(in-package :stoe/engine/render)
|
||||
|
||||
(defclass render-thread (specialized-thread)
|
||||
|
|
@ -96,3 +97,6 @@ Destroy the opengl context and the related resources."
|
|||
(render-world (get-world)))
|
||||
(update-clock clock)
|
||||
(compute-fps (clock-delta clock))))))
|
||||
|
||||
(defmacro on-render-thread (args &body body)
|
||||
`(eval-on-thread ,args *render-thread* ,@body))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue