1.0.6.9: micro-optimize portions of the reader
[sbcl.git] / src / code / thread.lisp
index 378fb4b..367b90d 100644 (file)
   #!+sb-doc
   "Mutex type."
   (name nil :type (or null simple-string))
-  (value nil))
+  (value nil)
+  #!+(and sb-lutex sb-thread)
+  (lutex (make-lutex)))
 
 (def!struct spinlock
   #!+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)
@@ -34,6 +36,7 @@ and the mutex is in use, sleep until it is available"
   (with-unique-names (got mutex1)
     `(let ((,mutex1 ,mutex)
            ,got)
+       (/show0 "WITH-MUTEX")
        (unwind-protect
             ;; FIXME: async unwind in SETQ form
             (when (setq ,got (get-mutex ,mutex1 ,value ,wait-p))
@@ -70,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))))))