Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sched/wait: Add wait_event_state()

Allows waiting with a custom @state.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20220822114648.989212021@infradead.org

+28
+28
include/linux/wait.h
··· 932 932 __ret; \ 933 933 }) 934 934 935 + #define __wait_event_state(wq, condition, state) \ 936 + ___wait_event(wq, condition, state, 0, 0, schedule()) 937 + 938 + /** 939 + * wait_event_state - sleep until a condition gets true 940 + * @wq_head: the waitqueue to wait on 941 + * @condition: a C expression for the event to wait for 942 + * @state: state to sleep in 943 + * 944 + * The process is put to sleep (@state) until the @condition evaluates to true 945 + * or a signal is received (when allowed by @state). The @condition is checked 946 + * each time the waitqueue @wq_head is woken up. 947 + * 948 + * wake_up() has to be called after changing any variable that could 949 + * change the result of the wait condition. 950 + * 951 + * The function will return -ERESTARTSYS if it was interrupted by a signal 952 + * (when allowed by @state) and 0 if @condition evaluated to true. 953 + */ 954 + #define wait_event_state(wq_head, condition, state) \ 955 + ({ \ 956 + int __ret = 0; \ 957 + might_sleep(); \ 958 + if (!(condition)) \ 959 + __ret = __wait_event_state(wq_head, condition, state); \ 960 + __ret; \ 961 + }) 962 + 935 963 #define __wait_event_killable_timeout(wq_head, condition, timeout) \ 936 964 ___wait_event(wq_head, ___wait_cond_timeout(condition), \ 937 965 TASK_KILLABLE, 0, timeout, \