1.0.6.9: micro-optimize portions of the reader
[sbcl.git] / src / code / thread.lisp
index 37e89ac..367b90d 100644 (file)
@@ -23,7 +23,7 @@
   #!+sb-doc
   "Spinlock type."
   (name nil :type (or null simple-string))
-  (value 0))
+  (value nil))
 
 (sb!xc:defmacro with-mutex ((mutex &key (value '*current-thread*) (wait-p t))
                             &body body)
@@ -73,3 +73,35 @@ provided the default value is used for the mutex."
            (release-mutex ,mutex1)))))
   #!-sb-thread
   `(locally ,@body))
+
+(sb!xc:defmacro with-recursive-spinlock ((spinlock) &body body)
+  #!-sb-thread
+  (declare (ignore spinlock))
+  #!+sb-thread
+  (with-unique-names (lock inner-lock-p got-it)
+    `(let* ((,lock ,spinlock)
+            (,inner-lock-p (eq (spinlock-value ,lock) *current-thread*))
+            (,got-it nil))
+       (unwind-protect
+            (when (or ,inner-lock-p (setf ,got-it (get-spinlock ,lock)))
+              (locally ,@body))
+         (when ,got-it
+           (release-spinlock ,lock)))))
+  #!-sb-thread
+  `(locally ,@body))
+
+(sb!xc:defmacro with-spinlock ((spinlock) &body body)
+  #!-sb-thread
+  (declare (ignore spinlock))
+  #!-sb-thread
+  `(locally ,@body)
+  #!+sb-thread
+  (with-unique-names (lock got-it)
+    `(let ((,lock ,spinlock)
+           (,got-it nil))
+      (unwind-protect
+           (progn
+             (setf ,got-it (get-spinlock ,lock))
+             (locally ,@body))
+        (when ,got-it
+          (release-spinlock ,lock))))))