dahdi: 'schluffen()' -> 'interruptible_sleep_on()' or 'wait_event_interruptible()'

'interruptible_sleep_on()' is the Linux equivalent of 'tsleep()'.  When
we're sleeping for a condition, we can also just use
wait_event_interruptible to close a potential race where the condition
goes true between the time we checked it and when we go to sleep waiting
on the event.

Signed-off-by: Shaun Ruffell <sruffell@digium.com>
Acked-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>

git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@9465 a0bf4364-ded3-4de4-8d8a-66a801d63aff
This commit is contained in:
Shaun Ruffell 2010-11-04 16:40:35 +00:00
parent 37097411ea
commit a782b4de71

View File

@ -996,26 +996,6 @@ void dahdi_qevent_lock(struct dahdi_chan *chan, int event)
spin_unlock_irqrestore(&chan->lock, flags); spin_unlock_irqrestore(&chan->lock, flags);
} }
/* sleep in user space until woken up. Equivilant of tsleep() in BSD */
static int schluffen(wait_queue_head_t *q)
{
DECLARE_WAITQUEUE(wait, current);
add_wait_queue(q, &wait);
current->state = TASK_INTERRUPTIBLE;
if (!signal_pending(current))
schedule();
current->state = TASK_RUNNING;
remove_wait_queue(q, &wait);
if (signal_pending(current))
return -ERESTARTSYS;
return 0;
}
static inline void calc_fcs(struct dahdi_chan *ss, int inwritebuf) static inline void calc_fcs(struct dahdi_chan *ss, int inwritebuf)
{ {
int x; int x;
@ -2094,7 +2074,8 @@ static ssize_t dahdi_chan_read(struct file *file, char __user *usrbuf,
break; break;
if (file->f_flags & O_NONBLOCK) if (file->f_flags & O_NONBLOCK)
return -EAGAIN; return -EAGAIN;
rv = schluffen(&chan->readbufq); rv = wait_event_interruptible(chan->readbufq,
(chan->outreadbuf > -1));
if (rv) if (rv)
return rv; return rv;
} }
@ -2221,11 +2202,11 @@ static ssize_t dahdi_chan_write(struct file *file, const char __user *usrbuf,
return -EAGAIN; return -EAGAIN;
} }
/* Wait for something to be available */ /* Wait for something to be available */
rv = schluffen(&chan->writebufq); rv = wait_event_interruptible(chan->writebufq,
if (rv) { (chan->inwritebuf >= 0));
if (rv)
return rv; return rv;
} }
}
amnt = count; amnt = count;
if (chan->flags & DAHDI_FLAG_LINEAR) { if (chan->flags & DAHDI_FLAG_LINEAR) {
@ -4656,9 +4637,9 @@ static int dahdi_ctl_ioctl(struct file *file, unsigned int cmd, unsigned long da
spin_unlock_irqrestore(&s->lock, flags); spin_unlock_irqrestore(&s->lock, flags);
if (rv) if (rv)
return rv; return rv;
rv = schluffen(&s->maintq); interruptible_sleep_on(&s->maintq);
if (rv) if (signal_pending(current))
return rv; return -ERESTARTSYS;
spin_lock_irqsave(&s->lock, flags); spin_lock_irqsave(&s->lock, flags);
break; break;
case DAHDI_MAINT_FAS_DEFECT: case DAHDI_MAINT_FAS_DEFECT:
@ -5076,9 +5057,12 @@ dahdi_chanandpseudo_ioctl(struct file *file, unsigned int cmd,
/* Know if there is a write pending */ /* Know if there is a write pending */
i = (chan->outwritebuf > -1); i = (chan->outwritebuf > -1);
spin_unlock_irqrestore(&chan->lock, flags); spin_unlock_irqrestore(&chan->lock, flags);
if (!i) break; /* skip if none */ if (!i)
rv = schluffen(&chan->writebufq); break; /* skip if none */
if (rv) return(rv); rv = wait_event_interruptible(chan->writebufq,
(chan->outwritebuf > -1));
if (rv)
return rv;
} }
break; break;
case DAHDI_IOMUX: /* wait for something to happen */ case DAHDI_IOMUX: /* wait for something to happen */
@ -5125,8 +5109,10 @@ dahdi_chanandpseudo_ioctl(struct file *file, unsigned int cmd,
put_user(ret, (int __user *)data); put_user(ret, (int __user *)data);
break; /* get out of loop */ break; /* get out of loop */
} }
rv = schluffen(&chan->eventbufq);
if (rv) return(rv); interruptible_sleep_on(&chan->eventbufq);
if (signal_pending(current))
return -ERESTARTSYS;
} }
/* clear IO MUX mask */ /* clear IO MUX mask */
chan->iomask = 0; chan->iomask = 0;
@ -5460,7 +5446,7 @@ static int dahdi_chan_ioctl(struct file *file, unsigned int cmd, unsigned long d
{ {
struct dahdi_chan *const chan = chan_from_file(file); struct dahdi_chan *const chan = chan_from_file(file);
unsigned long flags; unsigned long flags;
int j, rv; int j;
int ret; int ret;
int oldconf; int oldconf;
const void *rxgain = NULL; const void *rxgain = NULL;
@ -5787,8 +5773,9 @@ static int dahdi_chan_ioctl(struct file *file, unsigned int cmd, unsigned long d
spin_unlock_irqrestore(&chan->lock, flags); spin_unlock_irqrestore(&chan->lock, flags);
if (file->f_flags & O_NONBLOCK) if (file->f_flags & O_NONBLOCK)
return -EINPROGRESS; return -EINPROGRESS;
rv = schluffen(&chan->txstateq); interruptible_sleep_on(&chan->txstateq);
if (rv) return rv; if (signal_pending(current))
return -ERESTARTSYS;
break; break;
case DAHDI_FLASH: case DAHDI_FLASH:
spin_lock_irqsave(&chan->lock, flags); spin_lock_irqsave(&chan->lock, flags);
@ -5800,8 +5787,9 @@ static int dahdi_chan_ioctl(struct file *file, unsigned int cmd, unsigned long d
spin_unlock_irqrestore(&chan->lock, flags); spin_unlock_irqrestore(&chan->lock, flags);
if (file->f_flags & O_NONBLOCK) if (file->f_flags & O_NONBLOCK)
return -EINPROGRESS; return -EINPROGRESS;
rv = schluffen(&chan->txstateq); interruptible_sleep_on(&chan->txstateq);
if (rv) return rv; if (signal_pending(current))
return -ERESTARTSYS;
break; break;
case DAHDI_RINGOFF: case DAHDI_RINGOFF:
spin_lock_irqsave(&chan->lock, flags); spin_lock_irqsave(&chan->lock, flags);