There is a concept of synchronous polling for multiple device files in linux and I'm trying to understand how it works.
in linux 2.6.23 source drivers/char/random.c, I see following code
static DECLARE_WAIT_QUEUE_HEAD(random_read_wait);
static DECLARE_WAIT_QUEUE_HEAD(random_write_wait);
static unsigned int
random_poll(struct file *file, poll_table * wait)
{
unsigned int mask;
poll_wait(file, &random_read_wait, wait);
poll_wait(file, &random_write_wait, wait);
mask = 0;
if (input_pool.entropy_count >= random_read_wakeup_thresh)
mask |= POLLIN | POLLRDNORM;
if (input_pool.entropy_count < random_write_wakeup_thresh)
mask |= POLLOUT | POLLWRNORM;
return mask;
}
the poll_table is defined as below in include/linux/poll.h
typedef void (*poll_queue_proc)(struct file *, wait_queue_head_t *, struct poll_table_struct *);
typedef struct poll_table_struct {
poll_queue_proc qproc;
} poll_table;
I saw in a book (Ch.5, Essential Linux Device Drivers, Venkateswaran) that "The poll_table is a table of wait queues owned by device drivers that are being polled for data." but the source says it is just a function pointer. and I can't find what this function qproc is doing. Below is the function poll_wait defined in include/linux/poll.h.
static inline void poll_wait(struct file * filp, wait_queue_head_t * wait_address, poll_table *p)
{
if (p && wait_address)
p->qproc(filp, wait_address, p);
}
and in the book it says(about an example char driver for a mouse), "mouse_poll() uses the library function, poll_wait(), to add a wait queue (mouse_wait) to the kernel poll_table and go to sleep." so poll_wait can sleep, but in the random_poll() function above, we see tow consecutive poll_wait functions. so does the random_poll polls for read and write availability sequentially and sends the mask to the application? I would appreciate if someone can show me the example of poll_queue_proc function. I couldn't find it in the linux driver source(should it appear only in application?).