Re: [RFC UPDATE PATCH] add wait_event_*_lock() functions and comments

From: Arnd Bergmann
Date: Tue Feb 15 2005 - 13:02:00 EST


On Dinsdag 15 Februar 2005 02:04, Nishanth Aravamudan wrote:
> Here's at least one example:
>
> drivers/ieee1394/video1394.c:__video1394_ioctl()
>
AFAICS, that one should work just fine using after converting

while (d->buffer_status[v.buffer]!= VIDEO1394_BUFFER_READY) {
spin_unlock_irqrestore(&d->lock, flags);
interruptible_sleep_on(&d->waitq);
spin_lock_irqsave(&d->lock, flags);
if (signal_pending(current)) {
spin_unlock_irqrestore(&d->lock,flags);
return -EINTR;
}
}

to

static inline unsigned video1394_buffer_state(struct dma_iso_ctx *d,
unsigned int buffer)
{
unsigned long flags;
unsigned int ret;
spin_lock_irqsave(&d->lock, flags);
ret = d->buffer_status[buffer];
spin_unlock_irqrestore(&d->lock, flags);
return ret;
}
...

spin_unlock_irqrestore(&d->lock, flags);
if (wait_event_interruptible(d->waitq,
video1394_buffer_state(d, v.buffer) == VIDEO1394_BUFFER_READY))
return -EINTR;
spin_lock_irqsave(&d->lock, flags);

The trick here is that it is known in advance that the state does not actually
have to be protected by the lock after reading it, because the state can not
change from READY to FREE in any other place in the code.
One exception might be two processes calling the ioctl at the same time, but
I think that is racy will any of these variations.

Arnd <><


Attachment: pgp00000.pgp
Description: signature