X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?p=candle;a=blobdiff_plain;f=src%2Fmain%2Fprocessor.lisp;h=0d6ec1ec075a258699aa69c91370163f518f4fd0;hp=af65aa03946089780831cf5de48b0100851f4a5e;hb=92a8cc8928e1f5d6aa13708b35cb4551aa736a37;hpb=f0e0d6e5babe32e9c84f0ed224693fe0cfd83d9e diff --git a/src/main/processor.lisp b/src/main/processor.lisp index af65aa0..0d6ec1e 100644 --- a/src/main/processor.lisp +++ b/src/main/processor.lisp @@ -5,20 +5,35 @@ (defvar *job-system*) (defgeneric process-job-in-system (job-system job)) +(defgeneric shutdown-system (job-system)) (defun start-processor-thread () - (sb-thread:make-thread - (lambda () - (loop - (let - ((job (find :queued *all-job* :key #'job-status))) - (if job - (process-job job) - ; We just wait here until the processor is released, which is usually done - ; when a project is refreshed. - (sb-thread:with-mutex (*mutex*) - (sb-thread:condition-wait *waitq* *mutex*)))))) - :name "Processor")) + (format t "Starting processor in ~(~A~) mode~%" *job-system*) + (let* + ((active t) + (processor-thread + (sb-thread:make-thread + (lambda () + (loop + :while active + :do + (let + ((job (find :queued *all-job* :key #'job-status))) + (if job + (process-job job) + ; We just wait here until the processor is released, which is usually done + ; when a project is refreshed. + (sb-thread:with-mutex (*mutex*) + (sb-thread:condition-wait *waitq* *mutex*)))))) + :name "Processor"))) + (push + (lambda () + (format t "Shutting down processor thread~%") + (setf active nil) + (awaken-processor-thread) + (sb-thread:join-thread processor-thread) + (shutdown-system *job-system*)) + sb-ext:*exit-hooks*))) (defun awaken-processor-thread () (sb-thread:with-mutex (*mutex*)