- 論壇徽章:
- 0
|
本帖最后由 stuman 于 2014-07-05 19:51 編輯
- 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;
- }
復(fù)制代碼 以上是LDD中poll的代碼。按照書上的說法,當(dāng)沒有文件描述符可執(zhí)行I/O操作時,調(diào)用poll的進(jìn)程就會睡眠。但是這里使用poll_wait添加了兩個等待隊列,一個用于讀一個用于寫。那么內(nèi)核是如何判斷無法寫時在dev->outq上睡眠,而無法讀時在dev->inq上睡眠呢?
還有函數(shù)poll_wait中添加的等待隊列的用處到底是什么呢?如果使用poll查詢是否可以執(zhí)行非阻塞操作,那么根本不需要poll_wait函數(shù)呀。 |
|