linux join wait queue!
2012-08-06 15:21
211 查看
参考文章:http://blog.csdn.net/loyal_baby/article/details/4195946
进程通过执行下面几步将自己加入到一个等待队列中:
---------------------------------------------------------
1. 调用DECLARE_WAITQUEUE()创建一个等待队列的项
|------------------------------------------------|
|/* 'q' is the wait queue we wish to sleep on */ |
|DECLARE_WAITQUEUE(wait, current); |
|------------------------------------------------|
2. 调用add_wait_queue()把自己加入到队列中。该队列在进程等待的条件满足时唤醒它。当然我们必须在其他地方撰写相关代码,在事件发生时,对等待队列执行wake_up()操作
|-----------------------------|
|add_wait_queue(q, &wait); |
|-----------------------------|
while (!condition) { /* condition is the event that we are waiting for */
3. 将进程的状态变更为TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE
|----------------------------------------------|
| /* or TASK_UNINTERRUPTIBLE */ |
| set_current_state(TASK_INTERRUPTIBLE); |
|----------------------------------------------|
4. 如果状态被设置为TASK_INTERRUPTIBLE,则信号可以唤醒进程(信号和事件都可以唤醒该进程)。这就是所谓的伪唤醒(唤醒不是因为事件的发生,而是由信号唤醒的),因此检查并处理信号。
通过判定signal_pending(current)来确定是否有信号,而通过(!condition)来确定是否有事件,signal_pending(current)的作用主要是区分interruptable和Uninterruptable的。如果signal_pending(current)为真,即有信号,则处理信号后将再次让出CPU控制权(继续等待事件)。
|----------------------------------------------|
| if (signal_pending(current)) |
| /* handle signal */ |
|----------------------------------------------|
5. Tests whether the condition is true. If it is, there is no need to sleep. If it is not true, the task calls schedule().
本进程在此处交出CPU控制权,如果该进程再次被唤醒,将从while循环结尾处继续执行,因而将回到while循环的开始处while (!condition),进测等待事件是否真正发生.
|----------------------------------------------|
| schedule(); |
|----------------------------------------------|
}
进程通过执行下面几步将自己加入到一个等待队列中:
---------------------------------------------------------
1. 调用DECLARE_WAITQUEUE()创建一个等待队列的项
|------------------------------------------------|
|/* 'q' is the wait queue we wish to sleep on */ |
|DECLARE_WAITQUEUE(wait, current); |
|------------------------------------------------|
2. 调用add_wait_queue()把自己加入到队列中。该队列在进程等待的条件满足时唤醒它。当然我们必须在其他地方撰写相关代码,在事件发生时,对等待队列执行wake_up()操作
|-----------------------------|
|add_wait_queue(q, &wait); |
|-----------------------------|
while (!condition) { /* condition is the event that we are waiting for */
3. 将进程的状态变更为TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE
|----------------------------------------------|
| /* or TASK_UNINTERRUPTIBLE */ |
| set_current_state(TASK_INTERRUPTIBLE); |
|----------------------------------------------|
4. 如果状态被设置为TASK_INTERRUPTIBLE,则信号可以唤醒进程(信号和事件都可以唤醒该进程)。这就是所谓的伪唤醒(唤醒不是因为事件的发生,而是由信号唤醒的),因此检查并处理信号。
通过判定signal_pending(current)来确定是否有信号,而通过(!condition)来确定是否有事件,signal_pending(current)的作用主要是区分interruptable和Uninterruptable的。如果signal_pending(current)为真,即有信号,则处理信号后将再次让出CPU控制权(继续等待事件)。
|----------------------------------------------|
| if (signal_pending(current)) |
| /* handle signal */ |
|----------------------------------------------|
5. Tests whether the condition is true. If it is, there is no need to sleep. If it is not true, the task calls schedule().
本进程在此处交出CPU控制权,如果该进程再次被唤醒,将从while循环结尾处继续执行,因而将回到while循环的开始处while (!condition),进测等待事件是否真正发生.
|----------------------------------------------|
| schedule(); |
|----------------------------------------------|
}
相关文章推荐
- DECLARE_WAIT_QUEUE_HEAD(name)使用(linux3.1.0)
- linux等待队列wait_queue_head_t和wait_queue_t
- Linux等待队列wait_queue_head_t和wait_queue_t
- Linux内核等待队列wait_queue学习
- wait queue in linux kernel
- linux等待队列wait_queue_head_t和wait_queue_t
- Linux 设备驱动--- 内核等待队列 --- wait_queue_head --- wait_event_interruptible --- 按键驱动程序优化
- linux等待队列wait_queue_head_t和wait_queue_t
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- linux等待队列wait_queue_head_t和wait_queue_t
- linux等待队列wait_queue_head_t和wait_queue_t
- linux等待队列wait_queue_head_t和wait_queue_t
- linux内核部件分析之waitqueue与线程的阻塞
- linux driver wait queue
- linux等待队列wait_queue_head_t和wait_queue_t
- linux等待队列wait_queue_head_t和wait_queue_t
- Linux内核wait_queue深入分析
- linux内核wait_queue深入分析
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠
- linux内核的 等待队列 使用方法,wait_queue_head_t,进程休眠