master
Avril 6 years ago
parent 55bef09244
commit 9f22cf5f38
No known key found for this signature in database
GPG Key ID: DDDD9B6759158726

@ -0,0 +1,62 @@
;;Thing for atomising operations
(in-package :cl-box)
(flan-utils:enable-all-readers)
(defstruct %box
value
lock)
(defmacro %atomic (box &body re)
`(bt:with-lock-held ((%box-lock ,box))
,@re))
[
(defun make-box (&optional value)
(let ((b (make-%box)))
(setf (%box-value b) value)
(setf (%box-lock b) (bt:make-lock))
b))
(defun make (&optional value)
(make-box value))
(defun -> (box val)
(%atomic box
(setf (%box-value box) val)))
(defun <- (box)
(%atomic box
(%box-value box)))
(defun <-! (box)
(%box-value box))
(defun ->! (box val)
(setf (%box-value box) val))
(defun box-lock (box)
(%box-lock box))
(defsetf <- ->)
(defsetf @ ->)
(defun @ (box)
(<- box))
(defmacro --> (box &body things)
(let ((name (gensym)))
`(let ((,name ,box))
(bt:with-lock-held ((box-lock ,name))
(->! ,name (progn ,@things))
(<-! ,name)))))
(defmacro <-- (box &body things)
(let ((name (gensym)))
`(let ((,name ,box))
(bt:with-lock-held ((box-lock ,name))
(progn ,@things)
(<-! ,name)))))
]

@ -10,4 +10,5 @@
:bt-semaphore ) :bt-semaphore )
:components ((:file "package") :components ((:file "package")
(:file "cl-channel") (:file "cl-channel")
(:file "cl-box")
(:file "cl-dispatcher"))) (:file "cl-dispatcher")))

@ -7,3 +7,7 @@
(defpackage #:cl-dispatcher (defpackage #:cl-dispatcher
(:use #:cl) (:use #:cl)
(:nicknames :dispatcher)) (:nicknames :dispatcher))
(defpackage #:cl-box
(:use #:cl)
(:nicknames :box))

Loading…
Cancel
Save