|
有一段摘自内核里的驱动代码
上面的例子代码发错了,应该是这个
static ssize_t vhci_read(struct file *file,
char __user *buf, size_t count, loff_t *pos)
{
DECLARE_WAITQUEUE(wait, current);
struct vhci_data *data = file->private_data;
struct sk_buff *skb;
ssize_t ret = 0;
add_wait_queue(&data->read_wait, &wait);
while (count) {
set_current_state(TASK_INTERRUPTIBLE);
skb = skb_dequeue(&data->readq);
if (!skb) {
if (file->f_flags & O_NONBLOCK) {
ret = -EAGAIN;
break;
}
if (signal_pending(current)) {
ret = -ERESTARTSYS;
break;
}
schedule();
continue;
}
if (access_ok(VERIFY_WRITE, buf, count))
ret = vhci_put_user(data, skb, buf, count);
else
ret = -EFAULT;
kfree_skb(skb);
break;
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&data->read_wait, &wait);
return ret;
}
我的问题是,因为2.6的内核是可以被抢占的,
上面的vhci_read函数中, 如果读进程在执行set_current_state(TASK_INTERRUPTIBLE)之后
而skb = skb_dequeue(&data->readq)之前被抢占,那么是不是永远不会被唤醒呢(假设另外一个
写进程已经往data->readq放了点数据,并执行了wake_up_interruptiable操作,但读进程
还没有开始运行,错过了wake_up_interruptiable超作), |
|