+(sb!xc:defmacro with-mutex ((mutex &key value (wait-p t)) &body body)
+ #!+sb-doc
+ "Acquire MUTEX for the dynamic scope of BODY, setting it to
+NEW-VALUE or some suitable default value if NIL. If WAIT-P is non-NIL
+and the mutex is in use, sleep until it is available"
+ #!-sb-thread (declare (ignore mutex value wait-p))
+ #!+sb-thread
+ (with-unique-names (got)
+ `(let ((,got (get-mutex ,mutex ,value ,wait-p)))
+ (when ,got
+ (unwind-protect
+ (locally ,@body)
+ (release-mutex ,mutex)))))
+ ;; KLUDGE: this separate expansion for (NOT SB-THREAD) is not
+ ;; strictly necessary; GET-MUTEX and RELEASE-MUTEX are implemented.
+ ;; However, there would be a (possibly slight) performance hit in
+ ;; using them.
+ #!-sb-thread
+ `(locally ,@body))