(defun get-spinlock (lock offset new-value)
(declare (optimize (speed 3) (safety 0)))
+ ;; %instance-set-conditional can test for 0 (which is a fixnum) and
+ ;; store any value
(loop until
- (eql (sb!vm::%instance-set-conditional lock offset 0 new-value) 0)))
+ (eql (sb!vm::%instance-set-conditional lock offset 0 new-value) 0)))
-;; this should do nothing if we didn't own the lock, so safe to use in
-;; unwind-protect cleanups when lock acquisition failed for some reason
-(defun release-spinlock (lock offset our-value)
+(defun release-spinlock (lock offset)
(declare (optimize (speed 3) (safety 0)))
- (sb!vm::%instance-set-conditional lock offset our-value 0))
+ ;; %instance-set-conditional cannot compare arbitrary objects
+ ;; meaningfully, so
+ ;; (sb!vm::%instance-set-conditional lock offset our-value 0)
+ ;; does not work for bignum thread ids.
+ (sb!vm::%instance-set lock offset 0))
(defmacro with-spinlock ((queue) &body body)
(with-unique-names (pid)
(progn
(get-spinlock ,queue 2 ,pid)
,@body)
- (release-spinlock ,queue 2 ,pid)))))
+ (release-spinlock ,queue 2)))))
;;;; the higher-level locking operations are based on waitqueues
(assert (eql (mutex-lock l) 0) nil "6")
(describe l))
+(let ((l (make-waitqueue :name "spinlock"))
+ (p (current-thread-id)))
+ (assert (eql (waitqueue-lock l) 0) nil "1")
+ (with-spinlock (l)
+ (assert (eql (waitqueue-lock l) p) nil "2"))
+ (assert (eql (waitqueue-lock l) 0) nil "3")
+ (describe l))
+
;; test that SLEEP actually sleeps for at least the given time, even
;; if interrupted by another thread exiting/a gc/anything
(let ((start-time (get-universal-time)))
;;; checkins which aren't released. (And occasionally for internal
;;; versions, especially for internal versions off the main CVS
;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"0.9.1.59"
+"0.9.1.60"