fix job::wait-for-next-job to properly return the next available job

This commit is contained in:
Renaud Casenave-Péré 2014-10-22 10:25:58 +09:00
parent 9a32457848
commit 328879638b

View file

@ -11,6 +11,7 @@
:thread :thread
:containers) :containers)
(:export :job (:export :job
:job-result
:push-job :push-job
:wait-for-job :wait-for-job
:cancel-job)) :cancel-job))
@ -102,7 +103,7 @@ Returns t if the job has completed, nil otherwise."
(and waitp (and waitp
(with-mutex ((job-mutex job)) (with-mutex ((job-mutex job))
(if timeout (if timeout
(condition-wait(job-waitqueue job) (job-mutex job) :timeout timeout) (condition-wait (job-waitqueue job) (job-mutex job) :timeout timeout)
(loop until (job-completed job) (loop until (job-completed job)
do (condition-wait (job-waitqueue job) (job-mutex job)))) do (condition-wait (job-waitqueue job) (job-mutex job))))
(job-completed job))))) (job-completed job)))))
@ -149,7 +150,8 @@ Return t if job has been successfully canceled, nil if it currently running."
(condition-wait waitqueue lock) (condition-wait waitqueue lock)
(when (peek job-list) (when (peek job-list)
(setf job (dequeue job-list)) (setf job (dequeue job-list))
(setf (job-running job) t))))) (setf (job-running job) t))
job)))
(defun thread-loop (thread) (defun thread-loop (thread)
"Run the thread loop. "Run the thread loop.