poll 的实现

选自 ELDD

Sensing Data Availability

Poll ://synchronous, it may block the caller.

unsigned int (*poll) (struct file *, struct poll_table_struct *);

The following is the common module of its implementation.

static DECLARE_WAIT_QUEUE_HEAD(your_wait); /* Wait Queue */

static unsigned int
your_poll(struct file *file, poll_table *wait)
{
  poll_wait(file, &your_wait, wait);//add a wait queue (your_wait) to the kernel poll_table and go to sleep.
                                    //It will be wakeup in corresponding interrupt handler.
  spin_lock_irq(&your_lock);// your_lock is used to protect your device structure from
                            // concurrent accessing.

  /* See if data has arrived from the device or
     if the device is ready to accept more data */
  /* ... */
  spin_unlock_irq(&your_lock);

  /* Availability of data is detected from interrupt context */
  if (data_is_available()) return(POLLIN | POLLRDNORM);

  /* Data can be written. Not relevant for mice */
  if (data_can_be_written()) return(POLLOUT | POLLWRNORM);

  return 0;
}


//When change in data condition dectected, the arrival of new data from the device or new data can be accept,
// wake_up_interruptible(&your_wait) will be called to wake up the sleeping your_poll().

 

####

As the a synchronous

Fasync

you can refer ELDD for detail info.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值