From 45c2a2e4daee0f48ca79e7d4f37c4ae636ac2fb9 Mon Sep 17 00:00:00 2001 From: Gabor Melis Date: Mon, 20 Jun 2005 12:39:12 +0000 Subject: [PATCH] 0.9.1.60: * sb-thread::release-spinlock now releases the locks with non-fixnum value, but is no longer safe to call multiple times --- src/code/target-thread.lisp | 16 ++++++++++------ tests/threads.impure.lisp | 8 ++++++++ version.lisp-expr | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/code/target-thread.lisp b/src/code/target-thread.lisp index afe54b7..307af53 100644 --- a/src/code/target-thread.lisp +++ b/src/code/target-thread.lisp @@ -30,14 +30,18 @@ (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) @@ -46,7 +50,7 @@ (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 diff --git a/tests/threads.impure.lisp b/tests/threads.impure.lisp index 858d3da..41782bf 100644 --- a/tests/threads.impure.lisp +++ b/tests/threads.impure.lisp @@ -66,6 +66,14 @@ (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))) diff --git a/version.lisp-expr b/version.lisp-expr index d3995be..50e8c8e 100644 --- a/version.lisp-expr +++ b/version.lisp-expr @@ -17,4 +17,4 @@ ;;; 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" -- 1.7.10.4