在LDD3,我看到這樣的代碼爲什麼我們需要在poll中調用poll_wait?
static unsigned int scull_p_poll(struct file *filp, poll_table *wait)
{
struct scull_pipe *dev = filp->private_data;
unsigned int mask = 0;
/*
* The buffer is circular; it is considered full
* if "wp" is right behind "rp" and empty if the
* two are equal.
*/
down(&dev->sem);
poll_wait(filp, &dev->inq, wait);
poll_wait(filp, &dev->outq, wait);
if (dev->rp != dev->wp)
mask |= POLLIN | POLLRDNORM; /* readable */
if (spacefree(dev))
mask |= POLLOUT | POLLWRNORM; /* writable */
up(&dev->sem);
return mask;
}
但它說poll_wait不會等待,將立即返回。那爲什麼我們需要打電話呢?爲什麼我們不能只返回面具?
然後做的過程中睡眠時? – demonguy
@demonguy查看我的更新回答 –
您的意思是說,來自用戶空間的查詢調用會阻止進程,對不對? – demonguy