From e385e87fd1da4f48a906ba73fb5dc17f39de479c Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Wed, 2 Apr 2008 11:10:59 -0700 Subject: videobuf: Avoid deadlock with QBUF and bring up to spec for empty queue Add a waitqueue to wait on when there are no buffers in the buffer queue. DQBUF waits on this queue without holding vb_lock to allow a QBUF to happen. Once a buffer has been queued we recheck that the queue is still streaming and wait on the new buffer's waitqueue while holding the vb_lock. The driver should come along in a timely manner and put the buffer into its next state finishing the DQBUF. By implementing this waitqueue it also brings the videobuf DQBUF up to spec and it now blocks on O_NONBLOCK even when no buffers have been queued via QBUF: "By default VIDIOC_DQBUF blocks when no buffer is in the outgoing queue." - V4L2 spec CC: Trent Piepho CC: Carl Karsten CC: Jonathan Corbet Signed-off-by: Brandon Philips --- linux/drivers/media/video/videobuf-core.c | 96 +++++++++++++++++++++++------- linux/include/media/videobuf-core.h | 2 2 files changed, 78 insertions(+), 20 deletions(-) --- linux/include/media/videobuf-core.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'linux/include/media') diff --git a/linux/include/media/videobuf-core.h b/linux/include/media/videobuf-core.h index 7c80e8adf..18b0ba615 100644 --- a/linux/include/media/videobuf-core.h +++ b/linux/include/media/videobuf-core.h @@ -159,6 +159,8 @@ struct videobuf_queue { spinlock_t *irqlock; struct device *dev; + wait_queue_head_t wait; /* wait if queue is empty */ + enum v4l2_buf_type type; unsigned int inputs; /* for V4L2_BUF_FLAG_INPUT */ unsigned int msize; -- cgit v1.2.3