在linux网络驱动程序中:
ssize_t device_read(struct file *file,char *buffer,size_t length, loff_t *offset)
{
#ifdef _DEBUG
int i;
#endif
struct ed_device *edp;
DECLARE_WAITQUEUE(wait,current);
edp = (struct ed_device *)file->private_data;
add_wait_queue(&edp->rwait,&wait);
for(;;){
set_current_state(TASK_INTERRUPTIBLE);
if ( file->f_flags & O_NONBLOCK)
break;
if ( edp->tx_len > 0)
break;
if ( signal_pending(current))
break;
printk("Start going to sleep\n");
schedule();
printk("return from scheduler\n");
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&edp->rwait,&wait);
spin_lock(&edp->lock);
if(edp->tx_len == 0) {
spin_unlock(&edp->lock);
return 0;
}else
{...}
}
在简单应用程序中调用函数read(fd_tx, tx_ptr, BUFFER_SIZE-1)
后,内核进程device_read
进入休眠状态并打印信息Start going to sleep
。除非停止申请,否则永远不会被唤醒,然后打印信息return from scheduler
。
为什么wake_up_interruptible(&ed[ED_TX_DEVICE].rwait)
在其他函数中无法唤醒进程?