X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Fthread.lisp;h=367b90dcf7e7e9c33a676cad82ec4af0d46cc166;hb=cf0b72cd4052a09b9a305081524bd44e2948c1e5;hp=37e89acce878bd89c0875305c58b05d02444651d;hpb=402958f92506b9d3de852601b8c1ccb99b5ee558;p=sbcl.git diff --git a/src/code/thread.lisp b/src/code/thread.lisp index 37e89ac..367b90d 100644 --- a/src/code/thread.lisp +++ b/src/code/thread.lisp @@ -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))))))