0.9.1.60:
authorGabor Melis <mega@hotpop.com>
Mon, 20 Jun 2005 12:39:12 +0000 (12:39 +0000)
committerGabor Melis <mega@hotpop.com>
Mon, 20 Jun 2005 12:39:12 +0000 (12:39 +0000)
        * 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
tests/threads.impure.lisp
version.lisp-expr

index afe54b7..307af53 100644 (file)
 
 (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
index 858d3da..41782bf 100644 (file)
   (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)))
index d3995be..50e8c8e 100644 (file)
@@ -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"