-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path%atomic.lisp
More file actions
34 lines (31 loc) · 1.05 KB
/
%atomic.lisp
File metadata and controls
34 lines (31 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(uiop:define-package #:immutable/%atomic
(:use :cl)
(:shadowing-import-from :org.shirakumo.atomics
#:atomic-incf
#-sbcl #:defstruct)
(:shadow #:count)
(:export
#:define-atomic-counter
#:increment-atomic-counter))
(in-package #:immutable/%atomic)
#-sbcl
(defstruct atomic-counter
(count 0 :type fixnum))
(defmacro define-atomic-counter (name &optional (initial-value 0) documentation)
(check-type name symbol)
(check-type initial-value fixnum)
(check-type documentation (or null string))
#+sbcl
`(progn
(declaim (fixnum ,name))
(sb-ext:defglobal ,name ,initial-value ,@(when documentation (list documentation))))
#-sbcl
(progn
(declaim (atomic-counter ,name))
(defparameter ,name (make-atomic-counter :count ,initial-value)
,@(when documentation (list documentation)))))
(defmacro increment-atomic-counter (name &optional (delta 1))
(check-type name symbol)
`(atomic-incf #+sbcl ,name
#-sbcl (atomic-counter-count ,name)
,delta))