The character device driver in Linux has a function
Unsigned int (* poll) (struct file * FP, struct poll_table_struct * table)
This function is used within the system call select to hook the current file pointer to the wait defined inside the device.
Queue. The parameter table here can be ignored. It is an internal variable during the implementation of the select function.
Function implementation:
Wait_queue_head_t = (struct mydev *) filp-> private_data)-> wait_queue;
Poll_wait (filp, T, table );
Return mask;
Here mask can be:
Pollin | pollrdnorm
Pollout | pollwrnorm
And so on.
The role of poll_wait is:
Apply for an entry in the table, and each entry has a wait_queue_t. Then, Mount wait_queue_t to the queue of T, and then mount filp to the entry.
Here, filp is defined in the fdset of the select function.
Then in the driverProgramInternal, if data enters, it is called in the program
Wake_up_interruptible (& mydev-> wait_queue );