key 的poll




1、文件

/*
 * The input core
 *input.c

*/

2、fileops


static const struct file_operations input_devices_fileops = {

    .owner        = THIS_MODULE,
    .open        = input_proc_devices_open,
    .poll        = input_proc_devices_poll,
    .read        = seq_read,
    .llseek        = seq_lseek,
    .release    = seq_release,
};

3、poll

static unsigned int input_proc_devices_poll(struct file *file, poll_table *wait)
{
    poll_wait(file, &input_devices_poll_wait, wait);//等待中斷來喚醒
    if (file->f_version != input_devices_state) {
        file->f_version = input_devices_state;
        return POLLIN | POLLRDNORM;//返回
    }

    return 0;//返回後,應用端調用read。
}


4、wakeup

static inline void input_wakeup_procfs_readers(void)
{
    input_devices_state++;
    wake_up(&input_devices_poll_wait);//喚醒休眠
}


/**
 * input_register_handler - register a new input handler
 * @handler: handler to be registered
 *
 * This function registers a new input handler (interface) for input
 * devices in the system and attaches it to all input devices that
 * are compatible with the handler.
 */
int input_register_handler(struct input_handler *handler)
{
    struct input_dev *dev;
    int error;

    error = mutex_lock_interruptible(&input_mutex);
    if (error)
        return error;

    INIT_LIST_HEAD(&handler->h_list);

    list_add_tail(&handler->node, &input_handler_list);

    list_for_each_entry(dev, &input_dev_list, node)
        input_attach_handler(dev, handler);

    input_wakeup_procfs_readers();

    mutex_unlock(&input_mutex);
    return 0;
}
EXPORT_SYMBOL(input_register_handler);


5、


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章