Skip to content

Commit

Permalink
Simplify resource registration
Browse files Browse the repository at this point in the history
  • Loading branch information
borodust committed Aug 6, 2019
1 parent d638589 commit be7b395
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions resources/registry.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,20 @@
(defclass resource-registry (lockable)
((resource-table :initform (make-hash-table :test 'equal))))


(defvar *resource-registry* (make-instance 'resource-registry))


(defun register-resource (name handler)
(defun register-resource (name type &rest handler-opts &key &allow-other-keys)
(with-instance-lock-held (*resource-registry*)
(with-slots (resource-table) *resource-registry*
(with-hash-entries ((resource-entry (resource-name->string name))) resource-table
(let ((entry resource-entry))
(let ((entry resource-entry)
(handler (apply #'make-resource-handler type handler-opts)))
(when (and entry (not (eq entry handler)))
(warn "Resource redefinition: handler ~A for '~A' was registered earlier"
handler name)))
(setf resource-entry handler)))))
handler name))
(setf resource-entry handler))))))


(defun find-resource-handler (resource-name)
Expand Down Expand Up @@ -95,6 +97,6 @@
;;;
(defmacro defresource (resource-name type &body opts &key path &allow-other-keys)
`(progn
(register-resource ',resource-name (make-resource-handler ,type ,@opts))
(register-resource ',resource-name ,type ,@opts)
,@(when path
`((mount-filesystem ',resource-name ,path)))))

0 comments on commit be7b395

Please sign in to comment.