wait_event_interruptible()和wait_up_interruptible()

休眠

所谓休眠就是让出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)
{undefined
    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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值