X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Fcompare-and-swap.impure.lisp;h=e1dc09bfa94064376aae6302334e17addfeb94b6;hb=de3bfc084239fa962ef001eaa68e5b6f4b9bbf81;hp=f51559f109524fc3d7d31b37d0afce6ad5d3df4a;hpb=b71b8da241791687e7752f917ca032d937ba2bbf;p=sbcl.git diff --git a/tests/compare-and-swap.impure.lisp b/tests/compare-and-swap.impure.lisp index f51559f..e1dc09b 100644 --- a/tests/compare-and-swap.impure.lisp +++ b/tests/compare-and-swap.impure.lisp @@ -394,3 +394,54 @@ (assert (eq t (cas (thing b) nil :oops))) (assert (eq t (thing a))) (assert (eq t (thing b))))) + +;;; SYMBOL-VALUE with a constant argument used to return a bogus read-form +(with-test (:name :symbol-value-cas-expansion) + (multiple-value-bind (vars vals old new cas-form read-form) + (get-cas-expansion `(symbol-value t)) + (assert (not vars)) + (assert (not vals)) + (assert (eq t (eval read-form)))) + (multiple-value-bind (vars vals old new cas-form read-form) + (get-cas-expansion `(symbol-value *)) + (let ((* :foo)) + (assert (eq :foo + (eval `(let (,@(mapcar 'list vars vals)) + ,read-form))))) + (let ((* :bar)) + (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))))))