Skip to content

Commit

Permalink
handle concurrent package creation on server
Browse files Browse the repository at this point in the history
  • Loading branch information
lmj committed Apr 30, 2014
1 parent 883899d commit a1802ee
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lfarm-server.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,17 @@ closure in which those variables are bound to the captured values."
(let ,(mapcar #'list vars syms)
,@body)))))

(defmacro with-lock-predicate/wait (lock predicate &body body)
;; predicate intentionally evaluated twice
`(when ,predicate
(with-lock-held (,lock)
(when ,predicate
,@body))))

;;;; package generator

(defvar *package-creation-lock* (make-lock))

;;; Allegro and ABCL signal `reader-error' for a missing package
;;; during `read'. We must parse the report string in order to get the
;;; package name.
Expand Down Expand Up @@ -131,7 +140,9 @@ closure in which those variables are bound to the captured values."
(with-tag :retry
(flet ((make-package-and-retry (name)
(info "creating package" name)
(make-package name :use nil)
(with-lock-predicate/wait
*package-creation-lock* (not (find-package name))
(make-package name :use nil))
(go :retry)))
(with-missing-package-handler (#'make-package-and-retry)
(call-body)))))
Expand Down

0 comments on commit a1802ee

Please sign in to comment.