open("/dev/buttons", O_RDWR | O_NONBLOCK);非阻塞(立即返回一个数)
static DECLARE_MUTEX(button_lock); //定义互斥锁
if (file->f_flags & O_NONBLOCK)
{//非阻塞
if (down_trylock(&button_lock))
return -EBUSY;
}
else
{//阻塞
/* 获取信号量 */
down(&button_lock);
}
驱动read
if (file->f_flags & O_NONBLOCK){//非阻塞
if (!ev_press)
return -EAGAIN;
}
else
{//阻塞
/* 如果没有按键动作, 休眠 */
wait_event_interruptible(button_waitq, ev_press);
}