wait_event_interruptible(wq, condition)
用wake_up_interruptible()唤醒后,wait_event_interruptible(wq, condition)宏,自身再检查“condition”这个条件以决定是返回还是继续休眠,真则返回,假则继续睡眠,不过这个程序中若有中断程序的话,中断来了,还是会继续执行中断函数的。只有当执行wake_up_interruptible()并且condition条件成立时才会把程序从队列中唤醒。
结合驱动示例分析
static int touch_event_handler(void *unused)
{
do
{
mt65xx_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
set_current_state(TASK_INTERRUPTIBLE);
wait_event_interruptible(waiter, zintix_tpd_flag!=0);
zintix_tpd_flag = 0;
set_current_state (TASK_RUNNING);
mt65xx_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
if (tpd_touchinfo()) {
TPD_DEBUG_SET_TIME;
}
}while(!kthread_should_stop());
return 0;
}
static void tpd_eint_interrupt_handler(void)
{
printk("TPD interrup has been triggered\n");
// TPD_DEBUG_PRINT_INT;
zintix_tpd_flag = 1;
wake_up_interruptible(&waiter);
}
中断的时候,唤醒waiter,执行do()while