Wait in Linux kernel_ event_ interruptible_ Analysis of timeout interface

1. Prototype

  #define wait_ event_ interruptible_ timeout(wq_ head, condition, timeout) \
  ({ \
    long __ ret = timeout; \
    might_ sleep(); \
    if (!___ wait_ cond_ timeout(condition)) \
      __ ret = __ wait_ event_ interruptible_ timeout(wq_ head, \
                    condition, timeout); \
      __ ret; \
  })

2. Use scenarios

Sleep to meet the conditions or time out of sleep

3. It supports interruptible sleep, which means that it can send a signal to the sleep process, and the process will respond to the signal

4. Return value analysis

4.1 when the return value is greater than 0, it means that the remaining time (in Jiffy unit) is returned. If the condition is satisfied, that is, it has not timed out, and the condition has been reached, it will wake up

4.2 when the return value is 0, it means timeout and Automatic wake-up. At this time, handle the error according to the situation

Similar Posts: