休眠
所谓休眠就是让出CPU 然后并不返回
wait_event_interruptible(wq, condition)
condition = 0 ///休眠
condition = 1 ///唤醒
wait_event_interruptible()和wait_up_interruptible()
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
在补充一点知识:
wait_event_interruptible 是linux驱动设计中断的重要函数,他有什么用呢?
1 有什么用?
就是进程休眠,等待中断:
用在驱动里面会休眠当前的进程。
2 两个参数怎么用?
wait_event_interruptible(queue, condition)
1 queue 的中断队列里面有对应的中断产生
在linux kernel 里面 , wait.h 里面有个宏定义 : DECLARE_WAIT_QUEUE_HEAD 就是一个wait 等待的队列结构体
DECLARE_WAIT_QUEUE_HEAD queue 就是定义了一个等待的队列
2 condition设定条件符合
然后被休眠的进程如何重新启动呢?
3 如何唤醒
在中断进程里加入,或者别的进程里面加入
wake_up_interruptible(&queue)