Change 'ref' to 'deref'

This commit is contained in:
Justin Ethier 2019-06-13 13:04:44 -04:00
parent 9981ade6be
commit de0de090b4

View file

@ -20,7 +20,7 @@
make-atom make-atom
atom atom
atom? atom?
ref deref
swap! swap!
compare-and-set! compare-and-set!
;; Shared objects ;; Shared objects
@ -66,8 +66,8 @@
(%make-atom (make-shared (car obj))) (%make-atom (make-shared (car obj)))
(%make-atom #f))) (%make-atom #f)))
;; - ref atomic ;; - deref atomic
(define-c ref (define-c deref
"(void *data, int argc, closure _, object k, object obj)" "(void *data, int argc, closure _, object k, object obj)"
" atomic a; " atomic a;
Cyc_check_atomic(data, obj); Cyc_check_atomic(data, obj);
@ -88,7 +88,7 @@
;; That means the function can get called multiple times. That means it needs to be a pure function. Another thing is that you can't control the order of the function calls. If multiple threads are swapping to an Atom at the same time, order is out of the window. So make sure your functions are independent of order, like we talked about before. ;; That means the function can get called multiple times. That means it needs to be a pure function. Another thing is that you can't control the order of the function calls. If multiple threads are swapping to an Atom at the same time, order is out of the window. So make sure your functions are independent of order, like we talked about before.
;; ;;
(define (swap! atom f . args) (define (swap! atom f . args)
(let* ((oldval (ref atom)) (let* ((oldval (deref atom))
(newval (make-shared (apply f oldval args)))) (newval (make-shared (apply f oldval args))))
(if (compare-and-set! atom oldval newval) (if (compare-and-set! atom oldval newval)
newval ;; value did not change, return new one newval ;; value did not change, return new one