+#!+sb-thread
+(defvar *available-buffers-mutex* (sb!thread:make-mutex
+ :name "lock for *AVAILABLE-BUFFERS*")
+ #!+sb-doc
+ "Mutex for access to *AVAILABLE-BUFFERS*.")
+
+(defmacro with-available-buffers-lock ((&optional) &body body)
+ ;; WITHOUT-INTERRUPTS because streams are low-level enough to be
+ ;; async signal safe, and in particular a C-c that brings up the
+ ;; debugger while holding the mutex would lose badly
+ `(without-interrupts
+ (sb!thread:with-mutex (*available-buffers-mutex*)
+ ,@body)))
+