11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef _LINUX_WAIT_H 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define _LINUX_WAIT_H 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define WNOHANG 0x00000001 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define WUNTRACED 0x00000002 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define WSTOPPED WUNTRACED 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define WEXITED 0x00000004 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define WCONTINUED 0x00000008 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define WNOWAIT 0x01000000 /* Don't reap, just poll status. */ 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __WNOTHREAD 0x20000000 /* Don't wait on children of other threads in this group */ 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __WALL 0x40000000 /* Wait on all children, regardless of type */ 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */ 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* First argument to waitid: */ 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define P_ALL 0 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define P_PID 1 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define P_PGID 2 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef __KERNEL__ 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/list.h> 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/stddef.h> 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/spinlock.h> 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/current.h> 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldstypedef struct __wait_queue wait_queue_t; 287d47872146398dbede13223299fe1cb368ebc781Peter Zijlstratypedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key); 297d47872146398dbede13223299fe1cb368ebc781Peter Zijlstraint default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key); 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct __wait_queue { 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds unsigned int flags; 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define WQ_FLAG_EXCLUSIVE 0x01 34c43dc2fd885b5658cfd7cedb7bcca20910c517a4Benjamin LaHaise void *private; 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wait_queue_func_t func; 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct list_head task_list; 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct wait_bit_key { 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds void *flags; 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int bit_nr; 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct wait_bit_queue { 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct wait_bit_key key; 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wait_queue_t wait; 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstruct __wait_queue_head { 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds spinlock_t lock; 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct list_head task_list; 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldstypedef struct __wait_queue_head wait_queue_head_t; 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 558c65b4a60450590e79a28e9717ceffa9e4debb3fTim Schmielaustruct task_struct; 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Macros for declaration and initialisaton of the datatypes 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __WAITQUEUE_INITIALIZER(name, tsk) { \ 62c43dc2fd885b5658cfd7cedb7bcca20910c517a4Benjamin LaHaise .private = tsk, \ 631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .func = default_wake_function, \ 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .task_list = { NULL, NULL } } 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DECLARE_WAITQUEUE(name, tsk) \ 671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk) 681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \ 70e4d919188554a77c798a267e098059bc9aa39726Ingo Molnar .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ 711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .task_list = { &(name).task_list, &(name).task_list } } 721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DECLARE_WAIT_QUEUE_HEAD(name) \ 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name) 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __WAIT_BIT_KEY_INITIALIZER(word, bit) \ 771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds { .flags = word, .bit_nr = bit, } 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 79f07fdec50a13f134ea9608c8fb3f6408c58ef55ePeter Zijlstraextern void __init_waitqueue_head(wait_queue_head_t *q, const char *name, struct lock_class_key *); 802fc391112fb6f3424435a3aa2fda887497b5f807Peter Zijlstra 812fc391112fb6f3424435a3aa2fda887497b5f807Peter Zijlstra#define init_waitqueue_head(q) \ 822fc391112fb6f3424435a3aa2fda887497b5f807Peter Zijlstra do { \ 832fc391112fb6f3424435a3aa2fda887497b5f807Peter Zijlstra static struct lock_class_key __key; \ 842fc391112fb6f3424435a3aa2fda887497b5f807Peter Zijlstra \ 85f07fdec50a13f134ea9608c8fb3f6408c58ef55ePeter Zijlstra __init_waitqueue_head((q), #q, &__key); \ 862fc391112fb6f3424435a3aa2fda887497b5f807Peter Zijlstra } while (0) 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 887259f0d05d595b73ef312a082e628627c6414969Peter Zijlstra#ifdef CONFIG_LOCKDEP 897259f0d05d595b73ef312a082e628627c6414969Peter Zijlstra# define __WAIT_QUEUE_HEAD_INIT_ONSTACK(name) \ 907259f0d05d595b73ef312a082e628627c6414969Peter Zijlstra ({ init_waitqueue_head(&name); name; }) 917259f0d05d595b73ef312a082e628627c6414969Peter Zijlstra# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) \ 927259f0d05d595b73ef312a082e628627c6414969Peter Zijlstra wait_queue_head_t name = __WAIT_QUEUE_HEAD_INIT_ONSTACK(name) 937259f0d05d595b73ef312a082e628627c6414969Peter Zijlstra#else 947259f0d05d595b73ef312a082e628627c6414969Peter Zijlstra# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) DECLARE_WAIT_QUEUE_HEAD(name) 957259f0d05d595b73ef312a082e628627c6414969Peter Zijlstra#endif 967259f0d05d595b73ef312a082e628627c6414969Peter Zijlstra 971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p) 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds q->flags = 0; 100c43dc2fd885b5658cfd7cedb7bcca20910c517a4Benjamin LaHaise q->private = p; 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds q->func = default_wake_function; 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void init_waitqueue_func_entry(wait_queue_t *q, 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wait_queue_func_t func) 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds q->flags = 0; 108c43dc2fd885b5658cfd7cedb7bcca20910c517a4Benjamin LaHaise q->private = NULL; 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds q->func = func; 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int waitqueue_active(wait_queue_head_t *q) 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return !list_empty(&q->task_list); 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 117b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonextern void add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait); 118b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonextern void add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait); 119b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonextern void remove_wait_queue(wait_queue_head_t *q, wait_queue_t *wait); 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new) 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_add(&new->task_list, &head->task_list); 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Used for wake-one threads: 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 129a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gaostatic inline void __add_wait_queue_exclusive(wait_queue_head_t *q, 130a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao wait_queue_t *wait) 131a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao{ 132a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao wait->flags |= WQ_FLAG_EXCLUSIVE; 133a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao __add_wait_queue(q, wait); 134a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao} 135a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void __add_wait_queue_tail(wait_queue_head_t *head, 137a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao wait_queue_t *new) 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_add_tail(&new->task_list, &head->task_list); 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 142a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gaostatic inline void __add_wait_queue_tail_exclusive(wait_queue_head_t *q, 143a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao wait_queue_t *wait) 144a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao{ 145a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao wait->flags |= WQ_FLAG_EXCLUSIVE; 146a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao __add_wait_queue_tail(q, wait); 147a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao} 148a93d2f1744206827ccf416e2cdc5018aa503314eChangli Gao 1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline void __remove_wait_queue(wait_queue_head_t *head, 1501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wait_queue_t *old) 1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds list_del(&old->task_list); 1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 155b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonvoid __wake_up(wait_queue_head_t *q, unsigned int mode, int nr, void *key); 1564ede816ac36e027db5fe0051ad9c73f76db63772Davide Libenzivoid __wake_up_locked_key(wait_queue_head_t *q, unsigned int mode, void *key); 1574ede816ac36e027db5fe0051ad9c73f76db63772Davide Libenzivoid __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode, int nr, 1584ede816ac36e027db5fe0051ad9c73f76db63772Davide Libenzi void *key); 15963b2001169e75cd71e917ec953fdab572e3f944aThomas Gleixnervoid __wake_up_locked(wait_queue_head_t *q, unsigned int mode, int nr); 1604ede816ac36e027db5fe0051ad9c73f76db63772Davide Libenzivoid __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr); 161b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonvoid __wake_up_bit(wait_queue_head_t *, void *, int); 162b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonint __wait_on_bit(wait_queue_head_t *, struct wait_bit_queue *, int (*)(void *), unsigned); 163b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonint __wait_on_bit_lock(wait_queue_head_t *, struct wait_bit_queue *, int (*)(void *), unsigned); 164b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonvoid wake_up_bit(void *, int); 165b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonint out_of_line_wait_on_bit(void *, int, int (*)(void *), unsigned); 166b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonint out_of_line_wait_on_bit_lock(void *, int, int (*)(void *), unsigned); 167b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonwait_queue_head_t *bit_waitqueue(void *, int); 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 169e64d66c8edf11629aa203328daf898775ee27dd4Matthew Wilcox#define wake_up(x) __wake_up(x, TASK_NORMAL, 1, NULL) 170e64d66c8edf11629aa203328daf898775ee27dd4Matthew Wilcox#define wake_up_nr(x, nr) __wake_up(x, TASK_NORMAL, nr, NULL) 171e64d66c8edf11629aa203328daf898775ee27dd4Matthew Wilcox#define wake_up_all(x) __wake_up(x, TASK_NORMAL, 0, NULL) 17263b2001169e75cd71e917ec953fdab572e3f944aThomas Gleixner#define wake_up_locked(x) __wake_up_locked((x), TASK_NORMAL, 1) 17363b2001169e75cd71e917ec953fdab572e3f944aThomas Gleixner#define wake_up_all_locked(x) __wake_up_locked((x), TASK_NORMAL, 0) 174e64d66c8edf11629aa203328daf898775ee27dd4Matthew Wilcox 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define wake_up_interruptible(x) __wake_up(x, TASK_INTERRUPTIBLE, 1, NULL) 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define wake_up_interruptible_nr(x, nr) __wake_up(x, TASK_INTERRUPTIBLE, nr, NULL) 1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define wake_up_interruptible_all(x) __wake_up(x, TASK_INTERRUPTIBLE, 0, NULL) 178e64d66c8edf11629aa203328daf898775ee27dd4Matthew Wilcox#define wake_up_interruptible_sync(x) __wake_up_sync((x), TASK_INTERRUPTIBLE, 1) 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1800ccf831cbee94df9c5006dd46248c0f07847dd7cPeter Zijlstra/* 181c0da37753695e010776ccf2200a5731e0f88a9f3Davide Libenzi * Wakeup macros to be used to report events to the targets. 1820ccf831cbee94df9c5006dd46248c0f07847dd7cPeter Zijlstra */ 183c0da37753695e010776ccf2200a5731e0f88a9f3Davide Libenzi#define wake_up_poll(x, m) \ 184c0da37753695e010776ccf2200a5731e0f88a9f3Davide Libenzi __wake_up(x, TASK_NORMAL, 1, (void *) (m)) 185c0da37753695e010776ccf2200a5731e0f88a9f3Davide Libenzi#define wake_up_locked_poll(x, m) \ 186c0da37753695e010776ccf2200a5731e0f88a9f3Davide Libenzi __wake_up_locked_key((x), TASK_NORMAL, (void *) (m)) 187c0da37753695e010776ccf2200a5731e0f88a9f3Davide Libenzi#define wake_up_interruptible_poll(x, m) \ 188c0da37753695e010776ccf2200a5731e0f88a9f3Davide Libenzi __wake_up(x, TASK_INTERRUPTIBLE, 1, (void *) (m)) 189c0da37753695e010776ccf2200a5731e0f88a9f3Davide Libenzi#define wake_up_interruptible_sync_poll(x, m) \ 190c0da37753695e010776ccf2200a5731e0f88a9f3Davide Libenzi __wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m)) 1910ccf831cbee94df9c5006dd46248c0f07847dd7cPeter Zijlstra 1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __wait_event(wq, condition) \ 1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdo { \ 1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DEFINE_WAIT(__wait); \ 1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (;;) { \ 1971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \ 1981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (condition) \ 1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds schedule(); \ 2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds finish_wait(&wq, &__wait); \ 2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} while (0) 2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wait_event - sleep until a condition gets true 2071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @wq: the waitqueue to wait on 2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @condition: a C expression for the event to wait for 2091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the 2111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @condition evaluates to true. The @condition is checked each time 2121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the waitqueue @wq is woken up. 2131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wake_up() has to be called after changing any variable that could 2151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * change the result of the wait condition. 2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define wait_event(wq, condition) \ 2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdo { \ 2191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (condition) \ 2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 2211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __wait_event(wq, condition); \ 2221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} while (0) 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __wait_event_timeout(wq, condition, ret) \ 2251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdo { \ 2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DEFINE_WAIT(__wait); \ 2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (;;) { \ 2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \ 2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (condition) \ 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = schedule_timeout(ret); \ 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!ret) \ 2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds finish_wait(&wq, &__wait); \ 2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} while (0) 2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wait_event_timeout - sleep until a condition gets true or a timeout elapses 2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @wq: the waitqueue to wait on 2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @condition: a C expression for the event to wait for 2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @timeout: timeout, in jiffies 2441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the 2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @condition evaluates to true. The @condition is checked each time 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the waitqueue @wq is woken up. 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wake_up() has to be called after changing any variable that could 2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * change the result of the wait condition. 2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The function returns 0 if the @timeout elapsed, and the remaining 2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * jiffies if the condition evaluated to true before the timeout elapsed. 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define wait_event_timeout(wq, condition, timeout) \ 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds({ \ 2571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds long __ret = timeout; \ 2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!(condition)) \ 2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __wait_event_timeout(wq, condition, __ret); \ 2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __ret; \ 2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}) 2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __wait_event_interruptible(wq, condition, ret) \ 2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdo { \ 2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DEFINE_WAIT(__wait); \ 2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (;;) { \ 2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ 2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (condition) \ 2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!signal_pending(current)) { \ 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds schedule(); \ 2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; \ 2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = -ERESTARTSYS; \ 2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds finish_wait(&wq, &__wait); \ 2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} while (0) 2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wait_event_interruptible - sleep until a condition gets true 2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @wq: the waitqueue to wait on 2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @condition: a C expression for the event to wait for 2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The process is put to sleep (TASK_INTERRUPTIBLE) until the 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @condition evaluates to true or a signal is received. 2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The @condition is checked each time the waitqueue @wq is woken up. 2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wake_up() has to be called after changing any variable that could 2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * change the result of the wait condition. 2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The function will return -ERESTARTSYS if it was interrupted by a 2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * signal and 0 if @condition evaluated to true. 2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define wait_event_interruptible(wq, condition) \ 2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds({ \ 2981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int __ret = 0; \ 2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!(condition)) \ 3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __wait_event_interruptible(wq, condition, __ret); \ 3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __ret; \ 3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}) 3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __wait_event_interruptible_timeout(wq, condition, ret) \ 3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdo { \ 3061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DEFINE_WAIT(__wait); \ 3071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (;;) { \ 3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \ 3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (condition) \ 3111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!signal_pending(current)) { \ 3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = schedule_timeout(ret); \ 3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!ret) \ 3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; \ 3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = -ERESTARTSYS; \ 3191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 3211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds finish_wait(&wq, &__wait); \ 3221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} while (0) 3231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 3251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses 3261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @wq: the waitqueue to wait on 3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @condition: a C expression for the event to wait for 3281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @timeout: timeout, in jiffies 3291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The process is put to sleep (TASK_INTERRUPTIBLE) until the 3311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @condition evaluates to true or a signal is received. 3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The @condition is checked each time the waitqueue @wq is woken up. 3331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wake_up() has to be called after changing any variable that could 3351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * change the result of the wait condition. 3361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it 3381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * was interrupted by a signal, and the remaining jiffies otherwise 3391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * if the condition evaluated to true before the timeout elapsed. 3401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define wait_event_interruptible_timeout(wq, condition, timeout) \ 3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds({ \ 3431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds long __ret = timeout; \ 3441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!(condition)) \ 3451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __wait_event_interruptible_timeout(wq, condition, __ret); \ 3461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __ret; \ 3471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}) 3481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __wait_event_interruptible_exclusive(wq, condition, ret) \ 3501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdo { \ 3511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds DEFINE_WAIT(__wait); \ 3521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds \ 3531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (;;) { \ 3541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds prepare_to_wait_exclusive(&wq, &__wait, \ 3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds TASK_INTERRUPTIBLE); \ 356777c6c5f1f6e757ae49ecca2ed72d6b1f523c007Johannes Weiner if (condition) { \ 357777c6c5f1f6e757ae49ecca2ed72d6b1f523c007Johannes Weiner finish_wait(&wq, &__wait); \ 3581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 359777c6c5f1f6e757ae49ecca2ed72d6b1f523c007Johannes Weiner } \ 3601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!signal_pending(current)) { \ 3611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds schedule(); \ 3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; \ 3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 3641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ret = -ERESTARTSYS; \ 365777c6c5f1f6e757ae49ecca2ed72d6b1f523c007Johannes Weiner abort_exclusive_wait(&wq, &__wait, \ 366777c6c5f1f6e757ae49ecca2ed72d6b1f523c007Johannes Weiner TASK_INTERRUPTIBLE, NULL); \ 3671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds break; \ 3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } \ 3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} while (0) 3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define wait_event_interruptible_exclusive(wq, condition) \ 3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds({ \ 3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int __ret = 0; \ 3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!(condition)) \ 3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __wait_event_interruptible_exclusive(wq, condition, __ret);\ 3761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds __ret; \ 3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}) 3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 37922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz 38022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz#define __wait_event_interruptible_locked(wq, condition, exclusive, irq) \ 38122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz({ \ 38222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz int __ret = 0; \ 38322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz DEFINE_WAIT(__wait); \ 38422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz if (exclusive) \ 38522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz __wait.flags |= WQ_FLAG_EXCLUSIVE; \ 38622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz do { \ 38722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz if (likely(list_empty(&__wait.task_list))) \ 38822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz __add_wait_queue_tail(&(wq), &__wait); \ 38922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz set_current_state(TASK_INTERRUPTIBLE); \ 39022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz if (signal_pending(current)) { \ 39122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz __ret = -ERESTARTSYS; \ 39222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz break; \ 39322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz } \ 39422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz if (irq) \ 39522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz spin_unlock_irq(&(wq).lock); \ 39622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz else \ 39722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz spin_unlock(&(wq).lock); \ 39822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz schedule(); \ 39922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz if (irq) \ 40022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz spin_lock_irq(&(wq).lock); \ 40122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz else \ 40222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz spin_lock(&(wq).lock); \ 40322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz } while (!(condition)); \ 40422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz __remove_wait_queue(&(wq), &__wait); \ 40522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz __set_current_state(TASK_RUNNING); \ 40622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz __ret; \ 40722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz}) 40822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz 40922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz 41022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz/** 41122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * wait_event_interruptible_locked - sleep until a condition gets true 41222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @wq: the waitqueue to wait on 41322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @condition: a C expression for the event to wait for 41422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 41522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The process is put to sleep (TASK_INTERRUPTIBLE) until the 41622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @condition evaluates to true or a signal is received. 41722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The @condition is checked each time the waitqueue @wq is woken up. 41822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 41922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * It must be called with wq.lock being held. This spinlock is 42022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * unlocked while sleeping but @condition testing is done while lock 42122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * is held and when this macro exits the lock is held. 42222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 42322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The lock is locked/unlocked using spin_lock()/spin_unlock() 42422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * functions which must match the way they are locked/unlocked outside 42522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * of this macro. 42622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 42722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * wake_up_locked() has to be called after changing any variable that could 42822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * change the result of the wait condition. 42922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 43022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The function will return -ERESTARTSYS if it was interrupted by a 43122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * signal and 0 if @condition evaluated to true. 43222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz */ 43322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz#define wait_event_interruptible_locked(wq, condition) \ 43422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz ((condition) \ 43522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 0)) 43622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz 43722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz/** 43822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * wait_event_interruptible_locked_irq - sleep until a condition gets true 43922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @wq: the waitqueue to wait on 44022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @condition: a C expression for the event to wait for 44122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 44222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The process is put to sleep (TASK_INTERRUPTIBLE) until the 44322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @condition evaluates to true or a signal is received. 44422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The @condition is checked each time the waitqueue @wq is woken up. 44522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 44622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * It must be called with wq.lock being held. This spinlock is 44722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * unlocked while sleeping but @condition testing is done while lock 44822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * is held and when this macro exits the lock is held. 44922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 45022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq() 45122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * functions which must match the way they are locked/unlocked outside 45222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * of this macro. 45322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 45422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * wake_up_locked() has to be called after changing any variable that could 45522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * change the result of the wait condition. 45622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 45722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The function will return -ERESTARTSYS if it was interrupted by a 45822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * signal and 0 if @condition evaluated to true. 45922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz */ 46022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz#define wait_event_interruptible_locked_irq(wq, condition) \ 46122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz ((condition) \ 46222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 1)) 46322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz 46422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz/** 46522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * wait_event_interruptible_exclusive_locked - sleep exclusively until a condition gets true 46622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @wq: the waitqueue to wait on 46722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @condition: a C expression for the event to wait for 46822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 46922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The process is put to sleep (TASK_INTERRUPTIBLE) until the 47022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @condition evaluates to true or a signal is received. 47122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The @condition is checked each time the waitqueue @wq is woken up. 47222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 47322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * It must be called with wq.lock being held. This spinlock is 47422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * unlocked while sleeping but @condition testing is done while lock 47522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * is held and when this macro exits the lock is held. 47622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 47722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The lock is locked/unlocked using spin_lock()/spin_unlock() 47822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * functions which must match the way they are locked/unlocked outside 47922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * of this macro. 48022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 48122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag 48222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * set thus when other process waits process on the list if this 48322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * process is awaken further processes are not considered. 48422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 48522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * wake_up_locked() has to be called after changing any variable that could 48622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * change the result of the wait condition. 48722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 48822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The function will return -ERESTARTSYS if it was interrupted by a 48922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * signal and 0 if @condition evaluated to true. 49022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz */ 49122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz#define wait_event_interruptible_exclusive_locked(wq, condition) \ 49222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz ((condition) \ 49322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 0)) 49422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz 49522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz/** 49622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * wait_event_interruptible_exclusive_locked_irq - sleep until a condition gets true 49722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @wq: the waitqueue to wait on 49822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @condition: a C expression for the event to wait for 49922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 50022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The process is put to sleep (TASK_INTERRUPTIBLE) until the 50122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * @condition evaluates to true or a signal is received. 50222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The @condition is checked each time the waitqueue @wq is woken up. 50322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 50422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * It must be called with wq.lock being held. This spinlock is 50522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * unlocked while sleeping but @condition testing is done while lock 50622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * is held and when this macro exits the lock is held. 50722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 50822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq() 50922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * functions which must match the way they are locked/unlocked outside 51022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * of this macro. 51122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 51222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag 51322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * set thus when other process waits process on the list if this 51422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * process is awaken further processes are not considered. 51522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 51622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * wake_up_locked() has to be called after changing any variable that could 51722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * change the result of the wait condition. 51822c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * 51922c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * The function will return -ERESTARTSYS if it was interrupted by a 52022c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz * signal and 0 if @condition evaluated to true. 52122c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz */ 52222c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz#define wait_event_interruptible_exclusive_locked_irq(wq, condition) \ 52322c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz ((condition) \ 52422c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 1)) 52522c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz 52622c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz 52722c43c81a51e05f61e90445ceb59d486c12fd921Michal Nazarewicz 5281411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox#define __wait_event_killable(wq, condition, ret) \ 5291411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcoxdo { \ 5301411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox DEFINE_WAIT(__wait); \ 5311411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox \ 5321411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox for (;;) { \ 5331411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox prepare_to_wait(&wq, &__wait, TASK_KILLABLE); \ 5341411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox if (condition) \ 5351411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox break; \ 5361411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox if (!fatal_signal_pending(current)) { \ 5371411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox schedule(); \ 5381411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox continue; \ 5391411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox } \ 5401411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox ret = -ERESTARTSYS; \ 5411411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox break; \ 5421411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox } \ 5431411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox finish_wait(&wq, &__wait); \ 5441411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox} while (0) 5451411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox 5461411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox/** 5471411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * wait_event_killable - sleep until a condition gets true 5481411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * @wq: the waitqueue to wait on 5491411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * @condition: a C expression for the event to wait for 5501411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * 5511411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * The process is put to sleep (TASK_KILLABLE) until the 5521411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * @condition evaluates to true or a signal is received. 5531411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * The @condition is checked each time the waitqueue @wq is woken up. 5541411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * 5551411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * wake_up() has to be called after changing any variable that could 5561411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * change the result of the wait condition. 5571411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * 5581411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * The function will return -ERESTARTSYS if it was interrupted by a 5591411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox * signal and 0 if @condition evaluated to true. 5601411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox */ 5611411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox#define wait_event_killable(wq, condition) \ 5621411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox({ \ 5631411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox int __ret = 0; \ 5641411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox if (!(condition)) \ 5651411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox __wait_event_killable(wq, condition, __ret); \ 5661411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox __ret; \ 5671411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox}) 5681411d5a7fbe7dce1568b6f0a94c7cbc69eed1bfeMatthew Wilcox 5691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 5701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * These are the old interfaces to sleep waiting for an event. 5710fec171cdbd7763ef86cbaccb91f3708de6a9003Ingo Molnar * They are racy. DO NOT use them, use the wait_event* interfaces above. 5720fec171cdbd7763ef86cbaccb91f3708de6a9003Ingo Molnar * We plan to remove these interfaces. 5731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 5740fec171cdbd7763ef86cbaccb91f3708de6a9003Ingo Molnarextern void sleep_on(wait_queue_head_t *q); 5750fec171cdbd7763ef86cbaccb91f3708de6a9003Ingo Molnarextern long sleep_on_timeout(wait_queue_head_t *q, 5760fec171cdbd7763ef86cbaccb91f3708de6a9003Ingo Molnar signed long timeout); 5770fec171cdbd7763ef86cbaccb91f3708de6a9003Ingo Molnarextern void interruptible_sleep_on(wait_queue_head_t *q); 5780fec171cdbd7763ef86cbaccb91f3708de6a9003Ingo Molnarextern long interruptible_sleep_on_timeout(wait_queue_head_t *q, 5790fec171cdbd7763ef86cbaccb91f3708de6a9003Ingo Molnar signed long timeout); 5801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 5821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Waitqueues which are removed from the waitqueue_head at wakeup time 5831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 584b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonvoid prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state); 585b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonvoid prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state); 586b3c97528689619fc66569b30bf83d09d9929521aHarvey Harrisonvoid finish_wait(wait_queue_head_t *q, wait_queue_t *wait); 587777c6c5f1f6e757ae49ecca2ed72d6b1f523c007Johannes Weinervoid abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, 588777c6c5f1f6e757ae49ecca2ed72d6b1f523c007Johannes Weiner unsigned int mode, void *key); 5891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key); 5901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key); 5911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 592bf368e4e70cd4e0f880923c44e95a4273d725ab4Eric Dumazet#define DEFINE_WAIT_FUNC(name, function) \ 5931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds wait_queue_t name = { \ 594c43dc2fd885b5658cfd7cedb7bcca20910c517a4Benjamin LaHaise .private = current, \ 595bf368e4e70cd4e0f880923c44e95a4273d725ab4Eric Dumazet .func = function, \ 5967e43c84e3e5423ae72ae31e4cd7bbccfd1605194Paolo 'Blaisorblade' Giarrusso .task_list = LIST_HEAD_INIT((name).task_list), \ 5971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 5981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 599bf368e4e70cd4e0f880923c44e95a4273d725ab4Eric Dumazet#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function) 600bf368e4e70cd4e0f880923c44e95a4273d725ab4Eric Dumazet 6011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define DEFINE_WAIT_BIT(name, word, bit) \ 6021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct wait_bit_queue name = { \ 6031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .key = __WAIT_BIT_KEY_INITIALIZER(word, bit), \ 6041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .wait = { \ 605c43dc2fd885b5658cfd7cedb7bcca20910c517a4Benjamin LaHaise .private = current, \ 6061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .func = wake_bit_function, \ 6071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .task_list = \ 6081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds LIST_HEAD_INIT((name).wait.task_list), \ 6091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds }, \ 6101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 6111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define init_wait(wait) \ 6131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds do { \ 614c43dc2fd885b5658cfd7cedb7bcca20910c517a4Benjamin LaHaise (wait)->private = current; \ 6151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (wait)->func = autoremove_wake_function; \ 6161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds INIT_LIST_HEAD(&(wait)->task_list); \ 617231d0aefd88e94129cb8fb84794f9bb788c6366eEvgeny Kuznetsov (wait)->flags = 0; \ 6181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } while (0) 6191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 6211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wait_on_bit - wait for a bit to be cleared 6221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @word: the word being waited on, a kernel virtual address 6231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @bit: the bit of the word being waited on 6241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @action: the function used to sleep, which may take special actions 6251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @mode: the task state to sleep in 6261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 6271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * There is a standard hashed waitqueue table for generic use. This 6281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * is the part of the hashtable's accessor API that waits on a bit. 6291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * For instance, if one were to have waiters on a bitflag, one would 6301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * call wait_on_bit() in threads waiting for the bit to clear. 6311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * One uses wait_on_bit() where one is waiting for the bit to clear, 6321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * but has no intention of setting it. 6331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 6341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int wait_on_bit(void *word, int bit, 6351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int (*action)(void *), unsigned mode) 6361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!test_bit(bit, word)) 6381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 6391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return out_of_line_wait_on_bit(word, bit, action, mode); 6401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/** 6431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wait_on_bit_lock - wait for a bit to be cleared, when wanting to set it 6441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @word: the word being waited on, a kernel virtual address 6451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @bit: the bit of the word being waited on 6461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @action: the function used to sleep, which may take special actions 6471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * @mode: the task state to sleep in 6481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 6491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * There is a standard hashed waitqueue table for generic use. This 6501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * is the part of the hashtable's accessor API that waits on a bit 6511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * when one intends to set it, for instance, trying to lock bitflags. 6521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * For instance, if one were to have waiters trying to set bitflag 6531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * and waiting for it to clear before setting it, one would call 6541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * wait_on_bit() in threads waiting to be able to set the bit. 6551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * One uses wait_on_bit_lock() where one is waiting for the bit to 6561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * clear with the intention of setting it, and when done, clearing it. 6571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 6581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic inline int wait_on_bit_lock(void *word, int bit, 6591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int (*action)(void *), unsigned mode) 6601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 6611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!test_and_set_bit(bit, word)) 6621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 6631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return out_of_line_wait_on_bit_lock(word, bit, action, mode); 6641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 6651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* __KERNEL__ */ 6671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 669