From e34456da060d7972551b5868fe4db5a285a3091b Mon Sep 17 00:00:00 2001 From: Douglas Katzman Date: Fri, 14 Jul 2017 08:19:53 -0400 Subject: [PATCH] Improve ATOMIC-POP in a few ways (1) Don't reload from place on a failed CAS; use the CAS result. It appears that the previous code tried to do this, but the author mistook the behavior of "LOOP FOR" for "LOOP WITH". (2) Elide the final LISTP test. The cell whose CDR was stored back into place already satisfied LISTP. CAR doesn't need another test. (3) The simple form of LOOP generates significantly better code here, including elision of some moves and a useless initialization. --- src/code/late-cas.lisp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/code/late-cas.lisp b/src/code/late-cas.lisp index 376f3b8a3..74ec0b403 100644 --- a/src/code/late-cas.lisp +++ b/src/code/late-cas.lisp @@ -135,8 +135,8 @@ that no other thread modified PLACE between the read and the write. Works on all CASable places." (multiple-value-bind (vars vals old new cas-form read-form) (get-cas-expansion place env) - `(let* (,@(mapcar 'list vars vals)) - (loop for ,old = ,read-form - for ,new = (cdr ,old) - until (eq ,old (setf ,old ,cas-form)) - finally (return (car ,old)))))) + `(let* (,@(mapcar 'list vars vals) + (,old ,read-form)) + (loop (let ((,new (cdr ,old))) + (when (eq ,old (setf ,old ,cas-form)) + (return (car (truly-the list ,old))))))))) -- 2.11.4.GIT