请高手答疑(看linux设备驱动第一版pipe.c有疑问)
read_write_t scull_p_read (struct inode *inode, struct file *filp,char *buf, count_t count)
{
Scull_Pipe *dev = filp->private_data;
while (dev->rp == dev->wp) { /* nothing to read */
if (filp->f_flags & O_NONBLOCK)
return -EAGAIN;
PDEBUG("\"%s\" reading: going to sleep\n",current->comm);
interruptible_sleep_on(&dev->inq);
if (current->signal & ~current->blocked) /* a signal arrived */
return -ERESTARTSYS; /* tell the fs layer to handle it */
/* otherwise loop */
}
/* ok, data is there, return something */
if (dev->wp > dev->rp)
count = min(count, dev->wp - dev->rp);
else /* the write pointer has wrapped, return data up to dev->end */
count = min(count, dev->end - dev->rp);
memcpy_tofs(buf, dev->rp, count);
dev->rp += count;
if (dev->rp == dev->end)
dev->rp = dev->buffer; /* wrapped */
/* finally, awake any writers and return */
wake_up_interruptible(&dev->outq);
PDEBUG("\"%s\" did read %li bytes\n",current->comm, (long)count);
return count;
}
疑问一:第五行为什么是while不是if,个人觉得用if 才对
疑问二:24行怎么用了wake_up_interruptble函数,如果前面的while循环没有执行,也就是讲没有前面的interruptable_sleep_on函数,这也要wake up 进程吗?
thanks! 你怎么不看第二版
页:
[1]