Fix make-array transforms.
[sbcl.git] / tests / compare-and-swap.impure.lisp
index da4e2c9..e16e0cb 100644 (file)
@@ -3,7 +3,7 @@
 (defstruct xxx yyy)
 
 (macrolet ((test (init op)
-             `(with-test (:name (:cas :basics ,op))
+             `(with-test (:name (:cas :basics ,(intern (symbol-name op) "KEYWORD")))
                 (let ((x ,init)
                       (y (list 'foo))
                       (z (list 'bar)))
 (defstruct box
   (word 0 :type sb-vm:word))
 
+;; Have the following tests check that CAS access to the superclass
+;; works in the presence of a subclass sharing the conc-name.
+(defstruct (subbox (:include box) (:conc-name "BOX-")))
+
 (defun inc-box (box n)
   (declare (fixnum n) (box box))
   (loop repeat n
       (assert (eq :bar
                   (eval `(let (,@(mapcar 'list vars vals))
                       ,read-form)))))))
+
+(let ((foo (cons :foo nil)))
+  (defun cas-foo (old new)
+    (cas (cdr foo) old new)))
+
+(defcas foo () cas-foo)
+
+(with-test (:name :cas-and-macroexpansion)
+  (assert (not (cas (foo) nil t)))
+  (assert (eq t (cas (foo) t nil)))
+  (symbol-macrolet ((bar (foo)))
+    (assert (not (cas bar nil :ok)))
+    (assert (eq :ok (cas bar :ok nil)))
+    (assert (not (cas bar nil t)))))
+
+(with-test (:name :atomic-push
+            :skipped-on '(not :sb-thread))
+  (let ((store (cons nil nil))
+        (n 100000))
+    (symbol-macrolet ((x (car store))
+                      (y (cdr store)))
+      (dotimes (i n)
+        (push i y))
+      (mapc #'sb-thread:join-thread
+            (loop repeat (ecase sb-vm:n-word-bits (32 100) (64 1000))
+                  collect (sb-thread:make-thread
+                           (lambda ()
+                             (loop for z = (atomic-pop y)
+                                   while z
+                                   do (atomic-push z x)
+                                      (sleep 0.00001))))))
+      (assert (not y))
+      (assert (eql n (length x))))))