wait_event
2013-10-31 14:15
441 查看
Linux中是怎样实现wait 一个事件的?
1】定义一个wait queue head
static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);2】等待某个事件,当wakeup waitqueue时判断这个事件,也就是condition: a C expression for the event to wait for
struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty){
struct tty_ldisc *ld;
/* wait_event is a macro */
wait_event(tty_ldisc_wait, (ld = tty_ldisc_try(tty)) != NULL);
return ld;
}
3】唤醒waitqueue
void tty_ldisc_enable(struct tty_struct *tty){
set_bit(TTY_LDISC, &tty->flags);
clear_bit(TTY_LDISC_CHANGING, &tty->flags);
wake_up(&tty_ldisc_wait);
}
wait event 实现的原理
/*** wait_event - sleep until a condition gets true
* @wq: the waitqueue to wait on
* @condition: a C expression for the event to wait for
*
* The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
* @condition evaluates to true. The @condition is checked each time
* the waitqueue @wq is woken up.
*
* wake_up() has to be called after changing any variable that could
* change the result of the wait condition.
*/
#define wait_event(wq, condition) \
do { \
if (condition) \
break; \
__wait_event(wq, condition); \
} while (0)
#define __wait_event(wq, condition) \
do { \
DEFINE_WAIT(__wait); \
\
for (;;) { \
prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
if (condition) \
break; \
schedule(); \
} \
finish_wait(&wq, &__wait); \
} while (0)
相关文章推荐
- DllMain详解
- 包含块(containing block)的确定
- Rails中更改链接触发处理方式为异步
- 蓝屏 STOP:c0000218 {Registry File Failure}
- Master-Detail 查询 表体字符串合并
- Daily Scrum 10.30
- EDM电子邮件营销实施条件和邮件列表分析
- 全文索引快的原因以及contains与like查找区别比较
- Cairngorm框架使用总结
- HDU 3452 Bonsai
- NSSearchPathForDirectoriesInDomains用法
- D. Palindrome pairs
- Container With Most Water
- WM_PAINT、鼠标和键盘消息
- Daily Scrum 10.30
- paip.mysql 性能跟iops的以及硬盘缓存的关系
- (高精度运算4.7.27)UVA 10494 If We Were a Child Again(大数除法&&大数取余)
- poj 3735 Training little cats 构造矩阵
- warden container中安装软件
- SHUTDOWN: waiting for active calls to complete