+/**
+ * Wait until the FIFO gets below a certain size (if needed).
+ *
+ * Note that if more than one thread writes to the FIFO, you cannot assume that
+ * the FIFO is actually below the requested size upon return (since another
+ * thread could have refilled it already). This is typically not an issue, as
+ * this function is meant for (relaxed) congestion control.
+ *
+ * This function may be a cancellation point and it is cancel-safe.
+ *
+ * @param fifo queue to wait on
+ * @param max_depth wait until the queue has no more than this many blocks
+ * (use SIZE_MAX to ignore this constraint)
+ * @param max_size wait until the queue has no more than this many bytes
+ * (use SIZE_MAX to ignore this constraint)
+ * @return nothing.
+ */
+void block_FifoPace (block_fifo_t *fifo, size_t max_depth, size_t max_size)
+{
+ vlc_mutex_lock (&fifo->lock);
+ while ((fifo->i_depth > max_depth) || (fifo->i_size > max_size))
+ {
+ mutex_cleanup_push (&fifo->lock);
+ vlc_cond_wait (&fifo->wait_room, &fifo->lock);
+ vlc_cleanup_pop ();
+ }
+ vlc_mutex_unlock (&fifo->lock);
+}
+