QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1033|回复: 1

请高手答疑(看linux设备驱动第一版pipe.c有疑问)

[复制链接]
发表于 2004-8-21 11:42:21 | 显示全部楼层 |阅读模式
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!
发表于 2004-8-26 10:59:58 | 显示全部楼层
你怎么不看第二版
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-9-28 01:23 , Processed in 0.057832 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表