about wait_event() ,wait_event_interruptible and wait_event_interruptible_timeout()

本文详细解析了Linux内核中的等待队列实现机制,包括__wait_event、wait_event、wait_event_interruptible及其带超时的版本等关键宏定义。通过这些宏定义可以深入理解进程在特定条件下如何进入等待状态,并在条件满足时被唤醒。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

all of those are condition=0 cause waiting!!!!!!

First, we can see the prototype in the kernel!!!

__wait_event!!!!!!!!!!!!

#define __wait_event(wq, condition)      /
do {         /
 DEFINE_WAIT(__wait);      /
         /
 for (;;) {     //  it    is  an  infinite loop!!!!!!!!


  prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); /
  if (condition)      /
   break;      /
  schedule();      /
 }        /
 finish_wait(&wq, &__wait);     /
} while (0)

 

 

wait_event!!!!!!!!!!!!!!!

#define wait_event(wq, condition)      /
do {         /
 if (condition)//if condition is 0,waiting!!!!!!


break;       /
 __wait_event(wq, condition);     /
} while (0)

 

wait_event_interruptible!!!

#define wait_event_interruptible(wq, condition)  

{         
 int __ret = 0;       
 if (!(condition))      
  __wait_event_interruptible(wq, condition, __ret); 
 __ret;        
}

 

#define __wait_event_interruptible(wq, condition, ret)   /
do {         /
 DEFINE_WAIT(__wait);      /
         /
 for (;;) {       /
  prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); /
  if (condition)      /
   break;  
 
   /
  if (!signal_pending(current)) { 

schedule(); /
   continue;     /
  }       /
  ret = -ERESTARTSYS;     /
  break;       /
 }        /
 finish_wait(&wq, &__wait);     /
} while (0)

 

 

 

#define wait_event_interruptible_timeout(wq, condition, timeout) /
({         /
 long __ret = timeout;      /
 if (!(condition))      /
  __wait_event_interruptible_timeout(wq, condition, __ret); /
 __ret;        /
})

 

 

#define __wait_event_interruptible_timeout(wq, condition, ret)  /
do {         /
 DEFINE_WAIT(__wait);      /
         /
 for (;;) {       /
  prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); /
  if (condition)      /
   break;      /
  if (!signal_pending(current)) {    /if it is not wakened by a signal!!!!!!!


   ret = schedule_timeout(ret);   /a soft delay also schedule!!!!!


   if (!ret)     /
    break;     /
   continue;     /
  }       /
  ret = -ERESTARTSYS;     /
  break;       /
 }        /
 finish_wait(&wq, &__wait);     /
} while (0)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值