选自 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.