Function: SB-EXT:GET-CAS-EXPANSION

package type github

Analogous to GET-SETF-EXPANSION. Returns the following six values:

  • list of temporary variables
  • list of value-forms whose results those variable must be bound
  • temporary variable for the old value of PLACE
  • temporary variable for the new value of PLACE
  • form using the aforementioned temporaries which performs the compare-and-swap operation on PLACE
  • form using the aforementioned temporaries with which to perform a volatile read of PLACE

Example:

(get-cas-expansion ‘(car x)) ; => (#:CONS871), (X), #:OLD872, #:NEW873, ; (SB-KERNEL:%COMPARE-AND-SWAP-CAR #:CONS871 #:OLD872 :NEW873). ; (CAR #:CONS871)

(defmacro my-atomic-incf (place &optional (delta 1) &environment env) (multiple-value-bind (vars vals old new cas-form read-form) (get-cas-expansion place env) (let ((delta-value (gensym “DELTA”))) `(let* (,@(mapcar ‘list vars vals) (,old ,read-form) (,delta-value ,delta) (,new (+ ,old ,delta-value))) (loop until (eq ,old (setf ,old ,cas-form)) do (setf ,new (+ ,old ,delta-value))) ,new))))

EXPERIMENTAL: Interface subject to change.

Lambda list

(sb-impl::place &optional sb-impl::environment)