V4L/DVB (7488): videobuf: Simplify videobuf_waiton logic and possibly avoid missed wakeup

Possible missed wakeup- use kernel helpers for wait queues
  http://www.mail-archive.com/linux-usb-devel@lists.sourceforge.net/msg27983.html

Signed-off-by: Brandon Philips <bphilips@suse.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
This commit is contained in:
Brandon Philips
2008-04-02 18:10:59 -03:00
committed by Mauro Carvalho Chehab
parent b608f4323a
commit 009a90597e

View File

@@ -64,32 +64,25 @@ void *videobuf_alloc(struct videobuf_queue *q)
return vb; return vb;
} }
#define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\
vb->state != VIDEOBUF_QUEUED)
int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr) int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
{ {
int retval = 0;
DECLARE_WAITQUEUE(wait, current);
MAGIC_CHECK(vb->magic, MAGIC_BUFFER); MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
add_wait_queue(&vb->done, &wait);
while (vb->state == VIDEOBUF_ACTIVE || vb->state == VIDEOBUF_QUEUED) {
if (non_blocking) { if (non_blocking) {
retval = -EAGAIN; if (WAITON_CONDITION)
break; return 0;
else
return -EAGAIN;
} }
set_current_state(intr ? TASK_INTERRUPTIBLE
: TASK_UNINTERRUPTIBLE); if (intr)
if (vb->state == VIDEOBUF_ACTIVE || return wait_event_interruptible(vb->done, WAITON_CONDITION);
vb->state == VIDEOBUF_QUEUED) else
schedule(); wait_event(vb->done, WAITON_CONDITION);
set_current_state(TASK_RUNNING);
if (intr && signal_pending(current)) { return 0;
dprintk(1, "buffer waiton: -EINTR\n");
retval = -EINTR;
break;
}
}
remove_wait_queue(&vb->done, &wait);
return retval;
} }
int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb, int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,