|
select() 和 poll() 函数可以实现应用程序的输入输出复用函数。设备函数中的 poll() 内容结构较为简单,但多数设备驱动程序种的显示方式基本相同。关于应用程序里的 select() 和 poll() 相关内容见:
http://www.groad.net/bbs/read.php?tid-1251.html
http://www.groad.net/bbs/read.php?tid-1064.html
在驱动程序里实现输入输出复用不区分 select() 和 poll() 函数。file_operation 的 poll 域的函数结构如下:unsigned int xxx_poll (struct file *file, poll_table *wait);
应用程序调用 select() 函数或 poll() 函数时,设备驱动程序种的 poll() 函数有两种作用:
在内核的 poll_table 上注册成为 polling 对象的事件对应的等待队列。 内核向设备文件返回输入输出复用处理的 mask 值。
设备驱动程序中,实现 poll() 函数的方法具有一定的标准结构,如下所示:DECLARE_WAIT_QUEUE_HEAD(WaitQueue_Read);
DECLARE_WAIT_QUEUE_HEAD(WaitQueue_Write);
... ...
... ...
unsined int xxx_poll (struct file *file, poll_table *wait)
{
int mask = 0;
poll_wait (file, &WaitQueue_Read, wait);
poll_wait (file, &WaitQueue_Write, wait);
if (存在需要处理的输入数据)
mask |= (POLL | POLLRDNORM);
if (可输出)
mask |= (POLLOUT | POLLWRNORM);
return (mask);
}
相关实例:http://www.groad.net/bbs/read.php?tid-1353.html |
|