wait_event_timeout的理解
2017-01-10 22:28
519 查看
wait_event_timeout(wq, condition, timeout)
表示的有以下两个意思:
(1)当condition为真的时候,会返回
(2)当timeout到达时也会返回,不管此时condition为真为假都会返回
此时接着执行wait_event_timeout之后的代码,只要退出wait_event_timeout,进程就被置为TASK_RUNNING(因为源码中,在退出函数时,会调用到__set_current_state(TASK_RUNNING);)
这个函数是将进程睡眠,置状态为TASK_UNINTERRUPTIBLE直到condition为真,每一次调用唤 醒函数wake_up时都会检查condition,condition为假就继续等待,每次改变任何会导致condition变化的变量时候,都会调用wake_up()
函数返回0:表示timeout超时
返回一个正数:表示还没有超时,但condition变为真,返回剩余的时间
点击(此处)折叠或打开
/**
* wait_event_timeout - sleep until a condition gets true or a
timeout elapses
* @wq: the waitqueue to wait on
* @condition: a C expression for the event to wait for
* @timeout: timeout, in jiffies
*
* 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.
*
* The function returns 0 if the @timeout elapsed, or the
remaining
* jiffies (at least 1) if the
@condition evaluated to %true before
* the @timeout elapsed.
*/
查看源码,wait_event_timeout( )的返回值,是调用schedule_timeout()返回的
schedule_timeout()表示的进程睡眠直到时间超时,函数就会立即返回,除非进程状态被设置
有以下两种情况:
TASK_UNINTERRUPTIBLE:此时函数就会返回0,需要等待超时时间到才行
TASK_INTERRUPTIBLE:如果一个信号唤醒这个进程,函数就会提前返回,返回值为剩余的jiffies值;也可能是返回0,此时是超时时间刚好到
点击(此处)折叠或打开
/**
* schedule_timeout - sleep until timeout
* @timeout: timeout value in jiffies
*
* Make the current task sleep until @timeout jiffies have
* elapsed. The routine will return immediately unless
* the current task state has been set (see set_current_state()).
*
* You can set the task state as follows -
*
* %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to
* pass before the routine returns. The routine will return 0
*
* %TASK_INTERRUPTIBLE - the routine may return early if a
signal is
* delivered to the current task. In this case the
remaining time
* in jiffies will be returned, or 0 if the
timer expired in time
*
* The current task state is guaranteed to be TASK_RUNNING when this
* routine returns.
*
* Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule
* the CPU away without a bound on the timeout. In this case the
return
* value will be %MAX_SCHEDULE_TIMEOUT.
*
* In all cases the return value is guaranteed to be
non-negative
转自:http://blog.chinaunix.net/uid-30313399-id-5203964.html
表示的有以下两个意思:
(1)当condition为真的时候,会返回
(2)当timeout到达时也会返回,不管此时condition为真为假都会返回
此时接着执行wait_event_timeout之后的代码,只要退出wait_event_timeout,进程就被置为TASK_RUNNING(因为源码中,在退出函数时,会调用到__set_current_state(TASK_RUNNING);)
这个函数是将进程睡眠,置状态为TASK_UNINTERRUPTIBLE直到condition为真,每一次调用唤 醒函数wake_up时都会检查condition,condition为假就继续等待,每次改变任何会导致condition变化的变量时候,都会调用wake_up()
函数返回0:表示timeout超时
返回一个正数:表示还没有超时,但condition变为真,返回剩余的时间
点击(此处)折叠或打开
/**
* wait_event_timeout - sleep until a condition gets true or a
timeout elapses
* @wq: the waitqueue to wait on
* @condition: a C expression for the event to wait for
* @timeout: timeout, in jiffies
*
* 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.
*
* The function returns 0 if the @timeout elapsed, or the
remaining
* jiffies (at least 1) if the
@condition evaluated to %true before
* the @timeout elapsed.
*/
查看源码,wait_event_timeout( )的返回值,是调用schedule_timeout()返回的
schedule_timeout()表示的进程睡眠直到时间超时,函数就会立即返回,除非进程状态被设置
有以下两种情况:
TASK_UNINTERRUPTIBLE:此时函数就会返回0,需要等待超时时间到才行
TASK_INTERRUPTIBLE:如果一个信号唤醒这个进程,函数就会提前返回,返回值为剩余的jiffies值;也可能是返回0,此时是超时时间刚好到
点击(此处)折叠或打开
/**
* schedule_timeout - sleep until timeout
* @timeout: timeout value in jiffies
*
* Make the current task sleep until @timeout jiffies have
* elapsed. The routine will return immediately unless
* the current task state has been set (see set_current_state()).
*
* You can set the task state as follows -
*
* %TASK_UNINTERRUPTIBLE - at least @timeout jiffies are guaranteed to
* pass before the routine returns. The routine will return 0
*
* %TASK_INTERRUPTIBLE - the routine may return early if a
signal is
* delivered to the current task. In this case the
remaining time
* in jiffies will be returned, or 0 if the
timer expired in time
*
* The current task state is guaranteed to be TASK_RUNNING when this
* routine returns.
*
* Specifying a @timeout value of %MAX_SCHEDULE_TIMEOUT will schedule
* the CPU away without a bound on the timeout. In this case the
return
* value will be %MAX_SCHEDULE_TIMEOUT.
*
* In all cases the return value is guaranteed to be
non-negative
转自:http://blog.chinaunix.net/uid-30313399-id-5203964.html
相关文章推荐
- linux内核--wait_event_interruptible_timeout()函数分析
- 【Linux设备驱动程序(第三版)】----延迟:超时(wait_event_interruptible_timeout)
- 关于wait_event_timeout
- wait_event_interruptible_timeout
- Linux驱动中的 wait_event_interruptible 与 wake_up_interruptible 深度理解
- 查找出现“wait_event_timeout failed for session X”的原因
- wait_event_interruptible_timeout和schedule_timeout的区别
- wait_event_interruptible_timeout函数分析
- wait_event_interruptible_timeout和schedule_timeout的区别
- linux内核--wait_event_interruptible_timeout()函数分析
- wait_event_interruptible_timeout和schedule_timeout的区别
- wait_event_interruptible_timeout和schedule_timeout区别
- mysql事物锁等待超时,报错 Lock wait timeout exceeded; try restarting transaction
- 用ACE的Reactor模式实现网络通讯时,ACE内部用WSAEventSelect函数把网络事件与一个事件对象关联起来,目的是为了后面用WaitForMultipleObjects函数统一处理。
- Android中dispatchTouchEvent, onInterceptTouchEvent, onTouchEvent的理解
- 关于MySQL超出wait_timeout断开连接的问题
- 深入理解Yii2.0 (2)事件Event
- WaitForSingleObject函数用法及互斥对象的理解 .
- MySQL中的配置参数interactive_timeout和wait_timeout(可能导致过多sleep进程的两个参数)
- 解决方案:android monkeyrunner:Timeout while trying to create chimp mananger(device = MonkeyRunner.waitForConnection()一直报错的问题)