wait.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. #ifndef _LINUX_WAIT_H
  2. #define _LINUX_WAIT_H
  3. /*
  4. * Linux wait queue related types and methods
  5. */
  6. #include <linux/list.h>
  7. #include <linux/stddef.h>
  8. #include <linux/spinlock.h>
  9. #include <asm/current.h>
  10. #include <uapi/linux/wait.h>
  11. typedef struct __wait_queue wait_queue_t;
  12. typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
  13. int default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key);
  14. /* __wait_queue::flags */
  15. #define WQ_FLAG_EXCLUSIVE 0x01
  16. #define WQ_FLAG_WOKEN 0x02
  17. struct __wait_queue {
  18. unsigned int flags;
  19. void *private;
  20. wait_queue_func_t func;
  21. struct list_head task_list;
  22. };
  23. struct wait_bit_key {
  24. void *flags;
  25. int bit_nr;
  26. #define WAIT_ATOMIC_T_BIT_NR -1
  27. unsigned long timeout;
  28. };
  29. struct wait_bit_queue {
  30. struct wait_bit_key key;
  31. wait_queue_t wait;
  32. };
  33. struct __wait_queue_head {
  34. spinlock_t lock;
  35. struct list_head task_list;
  36. };
  37. typedef struct __wait_queue_head wait_queue_head_t;
  38. struct task_struct;
  39. /*
  40. * Macros for declaration and initialisaton of the datatypes
  41. */
  42. #define __WAITQUEUE_INITIALIZER(name, tsk) { \
  43. .private = tsk, \
  44. .func = default_wake_function, \
  45. .task_list = { NULL, NULL } }
  46. #define DECLARE_WAITQUEUE(name, tsk) \
  47. wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)
  48. #define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
  49. .lock = __SPIN_LOCK_UNLOCKED(name.lock), \
  50. .task_list = { &(name).task_list, &(name).task_list } }
  51. #define DECLARE_WAIT_QUEUE_HEAD(name) \
  52. wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
  53. #define __WAIT_BIT_KEY_INITIALIZER(word, bit) \
  54. { .flags = word, .bit_nr = bit, }
  55. #define __WAIT_ATOMIC_T_KEY_INITIALIZER(p) \
  56. { .flags = p, .bit_nr = WAIT_ATOMIC_T_BIT_NR, }
  57. extern void __init_waitqueue_head(wait_queue_head_t *q, const char *name, struct lock_class_key *);
  58. #define init_waitqueue_head(q) \
  59. do { \
  60. static struct lock_class_key __key; \
  61. \
  62. __init_waitqueue_head((q), #q, &__key); \
  63. } while (0)
  64. #ifdef CONFIG_LOCKDEP
  65. # define __WAIT_QUEUE_HEAD_INIT_ONSTACK(name) \
  66. ({ init_waitqueue_head(&name); name; })
  67. # define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) \
  68. wait_queue_head_t name = __WAIT_QUEUE_HEAD_INIT_ONSTACK(name)
  69. #else
  70. # define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) DECLARE_WAIT_QUEUE_HEAD(name)
  71. #endif
  72. static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
  73. {
  74. q->flags = 0;
  75. q->private = p;
  76. q->func = default_wake_function;
  77. }
  78. static inline void
  79. init_waitqueue_func_entry(wait_queue_t *q, wait_queue_func_t func)
  80. {
  81. q->flags = 0;
  82. q->private = NULL;
  83. q->func = func;
  84. }
  85. static inline int waitqueue_active(wait_queue_head_t *q)
  86. {
  87. return !list_empty(&q->task_list);
  88. }
  89. extern void add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait);
  90. extern void add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait);
  91. extern void remove_wait_queue(wait_queue_head_t *q, wait_queue_t *wait);
  92. static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
  93. {
  94. list_add(&new->task_list, &head->task_list);
  95. }
  96. /*
  97. * Used for wake-one threads:
  98. */
  99. static inline void
  100. __add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
  101. {
  102. wait->flags |= WQ_FLAG_EXCLUSIVE;
  103. __add_wait_queue(q, wait);
  104. }
  105. static inline void __add_wait_queue_tail(wait_queue_head_t *head,
  106. wait_queue_t *new)
  107. {
  108. list_add_tail(&new->task_list, &head->task_list);
  109. }
  110. static inline void
  111. __add_wait_queue_tail_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
  112. {
  113. wait->flags |= WQ_FLAG_EXCLUSIVE;
  114. __add_wait_queue_tail(q, wait);
  115. }
  116. static inline void
  117. __remove_wait_queue(wait_queue_head_t *head, wait_queue_t *old)
  118. {
  119. list_del(&old->task_list);
  120. }
  121. typedef int wait_bit_action_f(struct wait_bit_key *);
  122. void __wake_up(wait_queue_head_t *q, unsigned int mode, int nr, void *key);
  123. void __wake_up_locked_key(wait_queue_head_t *q, unsigned int mode, void *key);
  124. void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode, int nr, void *key);
  125. void __wake_up_locked(wait_queue_head_t *q, unsigned int mode, int nr);
  126. void __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr);
  127. void __wake_up_bit(wait_queue_head_t *, void *, int);
  128. int __wait_on_bit(wait_queue_head_t *, struct wait_bit_queue *, wait_bit_action_f *, unsigned);
  129. int __wait_on_bit_lock(wait_queue_head_t *, struct wait_bit_queue *, wait_bit_action_f *, unsigned);
  130. void wake_up_bit(void *, int);
  131. void wake_up_atomic_t(atomic_t *);
  132. int out_of_line_wait_on_bit(void *, int, wait_bit_action_f *, unsigned);
  133. int out_of_line_wait_on_bit_timeout(void *, int, wait_bit_action_f *, unsigned, unsigned long);
  134. int out_of_line_wait_on_bit_lock(void *, int, wait_bit_action_f *, unsigned);
  135. int out_of_line_wait_on_atomic_t(atomic_t *, int (*)(atomic_t *), unsigned);
  136. wait_queue_head_t *bit_waitqueue(void *, int);
  137. #define wake_up(x) __wake_up(x, TASK_NORMAL, 1, NULL)
  138. #define wake_up_nr(x, nr) __wake_up(x, TASK_NORMAL, nr, NULL)
  139. #define wake_up_all(x) __wake_up(x, TASK_NORMAL, 0, NULL)
  140. #define wake_up_locked(x) __wake_up_locked((x), TASK_NORMAL, 1)
  141. #define wake_up_all_locked(x) __wake_up_locked((x), TASK_NORMAL, 0)
  142. #define wake_up_interruptible(x) __wake_up(x, TASK_INTERRUPTIBLE, 1, NULL)
  143. #define wake_up_interruptible_nr(x, nr) __wake_up(x, TASK_INTERRUPTIBLE, nr, NULL)
  144. #define wake_up_interruptible_all(x) __wake_up(x, TASK_INTERRUPTIBLE, 0, NULL)
  145. #define wake_up_interruptible_sync(x) __wake_up_sync((x), TASK_INTERRUPTIBLE, 1)
  146. /*
  147. * Wakeup macros to be used to report events to the targets.
  148. */
  149. #define wake_up_poll(x, m) \
  150. __wake_up(x, TASK_NORMAL, 1, (void *) (m))
  151. #define wake_up_locked_poll(x, m) \
  152. __wake_up_locked_key((x), TASK_NORMAL, (void *) (m))
  153. #define wake_up_interruptible_poll(x, m) \
  154. __wake_up(x, TASK_INTERRUPTIBLE, 1, (void *) (m))
  155. #define wake_up_interruptible_sync_poll(x, m) \
  156. __wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m))
  157. #define ___wait_cond_timeout(condition) \
  158. ({ \
  159. bool __cond = (condition); \
  160. if (__cond && !__ret) \
  161. __ret = 1; \
  162. __cond || !__ret; \
  163. })
  164. #define ___wait_is_interruptible(state) \
  165. (!__builtin_constant_p(state) || \
  166. state == TASK_INTERRUPTIBLE || state == TASK_KILLABLE) \
  167. /*
  168. * The below macro ___wait_event() has an explicit shadow of the __ret
  169. * variable when used from the wait_event_*() macros.
  170. *
  171. * This is so that both can use the ___wait_cond_timeout() construct
  172. * to wrap the condition.
  173. *
  174. * The type inconsistency of the wait_event_*() __ret variable is also
  175. * on purpose; we use long where we can return timeout values and int
  176. * otherwise.
  177. */
  178. #define ___wait_event(wq, condition, state, exclusive, ret, cmd) \
  179. ({ \
  180. __label__ __out; \
  181. wait_queue_t __wait; \
  182. long __ret = ret; /* explicit shadow */ \
  183. \
  184. INIT_LIST_HEAD(&__wait.task_list); \
  185. if (exclusive) \
  186. __wait.flags = WQ_FLAG_EXCLUSIVE; \
  187. else \
  188. __wait.flags = 0; \
  189. \
  190. for (;;) { \
  191. long __int = prepare_to_wait_event(&wq, &__wait, state);\
  192. \
  193. if (condition) \
  194. break; \
  195. \
  196. if (___wait_is_interruptible(state) && __int) { \
  197. __ret = __int; \
  198. if (exclusive) { \
  199. abort_exclusive_wait(&wq, &__wait, \
  200. state, NULL); \
  201. goto __out; \
  202. } \
  203. break; \
  204. } \
  205. \
  206. cmd; \
  207. } \
  208. finish_wait(&wq, &__wait); \
  209. __out: __ret; \
  210. })
  211. #define __wait_event(wq, condition) \
  212. (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
  213. schedule())
  214. /**
  215. * wait_event - sleep until a condition gets true
  216. * @wq: the waitqueue to wait on
  217. * @condition: a C expression for the event to wait for
  218. *
  219. * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
  220. * @condition evaluates to true. The @condition is checked each time
  221. * the waitqueue @wq is woken up.
  222. *
  223. * wake_up() has to be called after changing any variable that could
  224. * change the result of the wait condition.
  225. */
  226. #define wait_event(wq, condition) \
  227. do { \
  228. might_sleep(); \
  229. if (condition) \
  230. break; \
  231. __wait_event(wq, condition); \
  232. } while (0)
  233. #define __wait_event_freezable(wq, condition) \
  234. ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0, \
  235. schedule(); try_to_freeze())
  236. /**
  237. * wait_event - sleep (or freeze) until a condition gets true
  238. * @wq: the waitqueue to wait on
  239. * @condition: a C expression for the event to wait for
  240. *
  241. * The process is put to sleep (TASK_INTERRUPTIBLE -- so as not to contribute
  242. * to system load) until the @condition evaluates to true. The
  243. * @condition is checked each time the waitqueue @wq is woken up.
  244. *
  245. * wake_up() has to be called after changing any variable that could
  246. * change the result of the wait condition.
  247. */
  248. #define wait_event_freezable(wq, condition) \
  249. ({ \
  250. int __ret = 0; \
  251. might_sleep(); \
  252. if (!(condition)) \
  253. __ret = __wait_event_freezable(wq, condition); \
  254. __ret; \
  255. })
  256. #define __wait_event_timeout(wq, condition, timeout) \
  257. ___wait_event(wq, ___wait_cond_timeout(condition), \
  258. TASK_UNINTERRUPTIBLE, 0, timeout, \
  259. __ret = schedule_timeout(__ret))
  260. /**
  261. * wait_event_timeout - sleep until a condition gets true or a timeout elapses
  262. * @wq: the waitqueue to wait on
  263. * @condition: a C expression for the event to wait for
  264. * @timeout: timeout, in jiffies
  265. *
  266. * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
  267. * @condition evaluates to true. The @condition is checked each time
  268. * the waitqueue @wq is woken up.
  269. *
  270. * wake_up() has to be called after changing any variable that could
  271. * change the result of the wait condition.
  272. *
  273. * Returns:
  274. * 0 if the @condition evaluated to %false after the @timeout elapsed,
  275. * 1 if the @condition evaluated to %true after the @timeout elapsed,
  276. * or the remaining jiffies (at least 1) if the @condition evaluated
  277. * to %true before the @timeout elapsed.
  278. */
  279. #define wait_event_timeout(wq, condition, timeout) \
  280. ({ \
  281. long __ret = timeout; \
  282. might_sleep(); \
  283. if (!___wait_cond_timeout(condition)) \
  284. __ret = __wait_event_timeout(wq, condition, timeout); \
  285. __ret; \
  286. })
  287. #define __wait_event_freezable_timeout(wq, condition, timeout) \
  288. ___wait_event(wq, ___wait_cond_timeout(condition), \
  289. TASK_INTERRUPTIBLE, 0, timeout, \
  290. __ret = schedule_timeout(__ret); try_to_freeze())
  291. /*
  292. * like wait_event_timeout() -- except it uses TASK_INTERRUPTIBLE to avoid
  293. * increasing load and is freezable.
  294. */
  295. #define wait_event_freezable_timeout(wq, condition, timeout) \
  296. ({ \
  297. long __ret = timeout; \
  298. might_sleep(); \
  299. if (!___wait_cond_timeout(condition)) \
  300. __ret = __wait_event_freezable_timeout(wq, condition, timeout); \
  301. __ret; \
  302. })
  303. #define __wait_event_cmd(wq, condition, cmd1, cmd2) \
  304. (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
  305. cmd1; schedule(); cmd2)
  306. /**
  307. * wait_event_cmd - sleep until a condition gets true
  308. * @wq: the waitqueue to wait on
  309. * @condition: a C expression for the event to wait for
  310. * @cmd1: the command will be executed before sleep
  311. * @cmd2: the command will be executed after sleep
  312. *
  313. * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
  314. * @condition evaluates to true. The @condition is checked each time
  315. * the waitqueue @wq is woken up.
  316. *
  317. * wake_up() has to be called after changing any variable that could
  318. * change the result of the wait condition.
  319. */
  320. #define wait_event_cmd(wq, condition, cmd1, cmd2) \
  321. do { \
  322. if (condition) \
  323. break; \
  324. __wait_event_cmd(wq, condition, cmd1, cmd2); \
  325. } while (0)
  326. #define __wait_event_interruptible(wq, condition) \
  327. ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0, \
  328. schedule())
  329. /**
  330. * wait_event_interruptible - sleep until a condition gets true
  331. * @wq: the waitqueue to wait on
  332. * @condition: a C expression for the event to wait for
  333. *
  334. * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  335. * @condition evaluates to true or a signal is received.
  336. * The @condition is checked each time the waitqueue @wq is woken up.
  337. *
  338. * wake_up() has to be called after changing any variable that could
  339. * change the result of the wait condition.
  340. *
  341. * The function will return -ERESTARTSYS if it was interrupted by a
  342. * signal and 0 if @condition evaluated to true.
  343. */
  344. #define wait_event_interruptible(wq, condition) \
  345. ({ \
  346. int __ret = 0; \
  347. might_sleep(); \
  348. if (!(condition)) \
  349. __ret = __wait_event_interruptible(wq, condition); \
  350. __ret; \
  351. })
  352. #define __wait_event_interruptible_timeout(wq, condition, timeout) \
  353. ___wait_event(wq, ___wait_cond_timeout(condition), \
  354. TASK_INTERRUPTIBLE, 0, timeout, \
  355. __ret = schedule_timeout(__ret))
  356. /**
  357. * wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses
  358. * @wq: the waitqueue to wait on
  359. * @condition: a C expression for the event to wait for
  360. * @timeout: timeout, in jiffies
  361. *
  362. * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  363. * @condition evaluates to true or a signal is received.
  364. * The @condition is checked each time the waitqueue @wq is woken up.
  365. *
  366. * wake_up() has to be called after changing any variable that could
  367. * change the result of the wait condition.
  368. *
  369. * Returns:
  370. * 0 if the @condition evaluated to %false after the @timeout elapsed,
  371. * 1 if the @condition evaluated to %true after the @timeout elapsed,
  372. * the remaining jiffies (at least 1) if the @condition evaluated
  373. * to %true before the @timeout elapsed, or -%ERESTARTSYS if it was
  374. * interrupted by a signal.
  375. */
  376. #define wait_event_interruptible_timeout(wq, condition, timeout) \
  377. ({ \
  378. long __ret = timeout; \
  379. might_sleep(); \
  380. if (!___wait_cond_timeout(condition)) \
  381. __ret = __wait_event_interruptible_timeout(wq, \
  382. condition, timeout); \
  383. __ret; \
  384. })
  385. #define __wait_event_hrtimeout(wq, condition, timeout, state) \
  386. ({ \
  387. int __ret = 0; \
  388. struct hrtimer_sleeper __t; \
  389. \
  390. hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, \
  391. HRTIMER_MODE_REL); \
  392. hrtimer_init_sleeper(&__t, current); \
  393. if ((timeout).tv64 != KTIME_MAX) \
  394. hrtimer_start_range_ns(&__t.timer, timeout, \
  395. current->timer_slack_ns, \
  396. HRTIMER_MODE_REL); \
  397. \
  398. __ret = ___wait_event(wq, condition, state, 0, 0, \
  399. if (!__t.task) { \
  400. __ret = -ETIME; \
  401. break; \
  402. } \
  403. schedule()); \
  404. \
  405. hrtimer_cancel(&__t.timer); \
  406. destroy_hrtimer_on_stack(&__t.timer); \
  407. __ret; \
  408. })
  409. /**
  410. * wait_event_hrtimeout - sleep until a condition gets true or a timeout elapses
  411. * @wq: the waitqueue to wait on
  412. * @condition: a C expression for the event to wait for
  413. * @timeout: timeout, as a ktime_t
  414. *
  415. * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
  416. * @condition evaluates to true or a signal is received.
  417. * The @condition is checked each time the waitqueue @wq is woken up.
  418. *
  419. * wake_up() has to be called after changing any variable that could
  420. * change the result of the wait condition.
  421. *
  422. * The function returns 0 if @condition became true, or -ETIME if the timeout
  423. * elapsed.
  424. */
  425. #define wait_event_hrtimeout(wq, condition, timeout) \
  426. ({ \
  427. int __ret = 0; \
  428. might_sleep(); \
  429. if (!(condition)) \
  430. __ret = __wait_event_hrtimeout(wq, condition, timeout, \
  431. TASK_UNINTERRUPTIBLE); \
  432. __ret; \
  433. })
  434. /**
  435. * wait_event_interruptible_hrtimeout - sleep until a condition gets true or a timeout elapses
  436. * @wq: the waitqueue to wait on
  437. * @condition: a C expression for the event to wait for
  438. * @timeout: timeout, as a ktime_t
  439. *
  440. * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  441. * @condition evaluates to true or a signal is received.
  442. * The @condition is checked each time the waitqueue @wq is woken up.
  443. *
  444. * wake_up() has to be called after changing any variable that could
  445. * change the result of the wait condition.
  446. *
  447. * The function returns 0 if @condition became true, -ERESTARTSYS if it was
  448. * interrupted by a signal, or -ETIME if the timeout elapsed.
  449. */
  450. #define wait_event_interruptible_hrtimeout(wq, condition, timeout) \
  451. ({ \
  452. long __ret = 0; \
  453. might_sleep(); \
  454. if (!(condition)) \
  455. __ret = __wait_event_hrtimeout(wq, condition, timeout, \
  456. TASK_INTERRUPTIBLE); \
  457. __ret; \
  458. })
  459. #define __wait_event_interruptible_exclusive(wq, condition) \
  460. ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, 0, \
  461. schedule())
  462. #define wait_event_interruptible_exclusive(wq, condition) \
  463. ({ \
  464. int __ret = 0; \
  465. might_sleep(); \
  466. if (!(condition)) \
  467. __ret = __wait_event_interruptible_exclusive(wq, condition);\
  468. __ret; \
  469. })
  470. #define __wait_event_freezable_exclusive(wq, condition) \
  471. ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, 0, \
  472. schedule(); try_to_freeze())
  473. #define wait_event_freezable_exclusive(wq, condition) \
  474. ({ \
  475. int __ret = 0; \
  476. might_sleep(); \
  477. if (!(condition)) \
  478. __ret = __wait_event_freezable_exclusive(wq, condition);\
  479. __ret; \
  480. })
  481. #define __wait_event_interruptible_locked(wq, condition, exclusive, irq) \
  482. ({ \
  483. int __ret = 0; \
  484. DEFINE_WAIT(__wait); \
  485. if (exclusive) \
  486. __wait.flags |= WQ_FLAG_EXCLUSIVE; \
  487. do { \
  488. if (likely(list_empty(&__wait.task_list))) \
  489. __add_wait_queue_tail(&(wq), &__wait); \
  490. set_current_state(TASK_INTERRUPTIBLE); \
  491. if (signal_pending(current)) { \
  492. __ret = -ERESTARTSYS; \
  493. break; \
  494. } \
  495. if (irq) \
  496. spin_unlock_irq(&(wq).lock); \
  497. else \
  498. spin_unlock(&(wq).lock); \
  499. schedule(); \
  500. if (irq) \
  501. spin_lock_irq(&(wq).lock); \
  502. else \
  503. spin_lock(&(wq).lock); \
  504. } while (!(condition)); \
  505. __remove_wait_queue(&(wq), &__wait); \
  506. __set_current_state(TASK_RUNNING); \
  507. __ret; \
  508. })
  509. /**
  510. * wait_event_interruptible_locked - sleep until a condition gets true
  511. * @wq: the waitqueue to wait on
  512. * @condition: a C expression for the event to wait for
  513. *
  514. * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  515. * @condition evaluates to true or a signal is received.
  516. * The @condition is checked each time the waitqueue @wq is woken up.
  517. *
  518. * It must be called with wq.lock being held. This spinlock is
  519. * unlocked while sleeping but @condition testing is done while lock
  520. * is held and when this macro exits the lock is held.
  521. *
  522. * The lock is locked/unlocked using spin_lock()/spin_unlock()
  523. * functions which must match the way they are locked/unlocked outside
  524. * of this macro.
  525. *
  526. * wake_up_locked() has to be called after changing any variable that could
  527. * change the result of the wait condition.
  528. *
  529. * The function will return -ERESTARTSYS if it was interrupted by a
  530. * signal and 0 if @condition evaluated to true.
  531. */
  532. #define wait_event_interruptible_locked(wq, condition) \
  533. ((condition) \
  534. ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 0))
  535. /**
  536. * wait_event_interruptible_locked_irq - sleep until a condition gets true
  537. * @wq: the waitqueue to wait on
  538. * @condition: a C expression for the event to wait for
  539. *
  540. * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  541. * @condition evaluates to true or a signal is received.
  542. * The @condition is checked each time the waitqueue @wq is woken up.
  543. *
  544. * It must be called with wq.lock being held. This spinlock is
  545. * unlocked while sleeping but @condition testing is done while lock
  546. * is held and when this macro exits the lock is held.
  547. *
  548. * The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq()
  549. * functions which must match the way they are locked/unlocked outside
  550. * of this macro.
  551. *
  552. * wake_up_locked() has to be called after changing any variable that could
  553. * change the result of the wait condition.
  554. *
  555. * The function will return -ERESTARTSYS if it was interrupted by a
  556. * signal and 0 if @condition evaluated to true.
  557. */
  558. #define wait_event_interruptible_locked_irq(wq, condition) \
  559. ((condition) \
  560. ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 1))
  561. /**
  562. * wait_event_interruptible_exclusive_locked - sleep exclusively until a condition gets true
  563. * @wq: the waitqueue to wait on
  564. * @condition: a C expression for the event to wait for
  565. *
  566. * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  567. * @condition evaluates to true or a signal is received.
  568. * The @condition is checked each time the waitqueue @wq is woken up.
  569. *
  570. * It must be called with wq.lock being held. This spinlock is
  571. * unlocked while sleeping but @condition testing is done while lock
  572. * is held and when this macro exits the lock is held.
  573. *
  574. * The lock is locked/unlocked using spin_lock()/spin_unlock()
  575. * functions which must match the way they are locked/unlocked outside
  576. * of this macro.
  577. *
  578. * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag
  579. * set thus when other process waits process on the list if this
  580. * process is awaken further processes are not considered.
  581. *
  582. * wake_up_locked() has to be called after changing any variable that could
  583. * change the result of the wait condition.
  584. *
  585. * The function will return -ERESTARTSYS if it was interrupted by a
  586. * signal and 0 if @condition evaluated to true.
  587. */
  588. #define wait_event_interruptible_exclusive_locked(wq, condition) \
  589. ((condition) \
  590. ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 0))
  591. /**
  592. * wait_event_interruptible_exclusive_locked_irq - sleep until a condition gets true
  593. * @wq: the waitqueue to wait on
  594. * @condition: a C expression for the event to wait for
  595. *
  596. * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  597. * @condition evaluates to true or a signal is received.
  598. * The @condition is checked each time the waitqueue @wq is woken up.
  599. *
  600. * It must be called with wq.lock being held. This spinlock is
  601. * unlocked while sleeping but @condition testing is done while lock
  602. * is held and when this macro exits the lock is held.
  603. *
  604. * The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq()
  605. * functions which must match the way they are locked/unlocked outside
  606. * of this macro.
  607. *
  608. * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag
  609. * set thus when other process waits process on the list if this
  610. * process is awaken further processes are not considered.
  611. *
  612. * wake_up_locked() has to be called after changing any variable that could
  613. * change the result of the wait condition.
  614. *
  615. * The function will return -ERESTARTSYS if it was interrupted by a
  616. * signal and 0 if @condition evaluated to true.
  617. */
  618. #define wait_event_interruptible_exclusive_locked_irq(wq, condition) \
  619. ((condition) \
  620. ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 1))
  621. #define __wait_event_killable(wq, condition) \
  622. ___wait_event(wq, condition, TASK_KILLABLE, 0, 0, schedule())
  623. /**
  624. * wait_event_killable - sleep until a condition gets true
  625. * @wq: the waitqueue to wait on
  626. * @condition: a C expression for the event to wait for
  627. *
  628. * The process is put to sleep (TASK_KILLABLE) until the
  629. * @condition evaluates to true or a signal is received.
  630. * The @condition is checked each time the waitqueue @wq is woken up.
  631. *
  632. * wake_up() has to be called after changing any variable that could
  633. * change the result of the wait condition.
  634. *
  635. * The function will return -ERESTARTSYS if it was interrupted by a
  636. * signal and 0 if @condition evaluated to true.
  637. */
  638. #define wait_event_killable(wq, condition) \
  639. ({ \
  640. int __ret = 0; \
  641. might_sleep(); \
  642. if (!(condition)) \
  643. __ret = __wait_event_killable(wq, condition); \
  644. __ret; \
  645. })
  646. #define __wait_event_lock_irq(wq, condition, lock, cmd) \
  647. (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
  648. spin_unlock_irq(&lock); \
  649. cmd; \
  650. schedule(); \
  651. spin_lock_irq(&lock))
  652. /**
  653. * wait_event_lock_irq_cmd - sleep until a condition gets true. The
  654. * condition is checked under the lock. This
  655. * is expected to be called with the lock
  656. * taken.
  657. * @wq: the waitqueue to wait on
  658. * @condition: a C expression for the event to wait for
  659. * @lock: a locked spinlock_t, which will be released before cmd
  660. * and schedule() and reacquired afterwards.
  661. * @cmd: a command which is invoked outside the critical section before
  662. * sleep
  663. *
  664. * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
  665. * @condition evaluates to true. The @condition is checked each time
  666. * the waitqueue @wq is woken up.
  667. *
  668. * wake_up() has to be called after changing any variable that could
  669. * change the result of the wait condition.
  670. *
  671. * This is supposed to be called while holding the lock. The lock is
  672. * dropped before invoking the cmd and going to sleep and is reacquired
  673. * afterwards.
  674. */
  675. #define wait_event_lock_irq_cmd(wq, condition, lock, cmd) \
  676. do { \
  677. if (condition) \
  678. break; \
  679. __wait_event_lock_irq(wq, condition, lock, cmd); \
  680. } while (0)
  681. /**
  682. * wait_event_lock_irq - sleep until a condition gets true. The
  683. * condition is checked under the lock. This
  684. * is expected to be called with the lock
  685. * taken.
  686. * @wq: the waitqueue to wait on
  687. * @condition: a C expression for the event to wait for
  688. * @lock: a locked spinlock_t, which will be released before schedule()
  689. * and reacquired afterwards.
  690. *
  691. * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
  692. * @condition evaluates to true. The @condition is checked each time
  693. * the waitqueue @wq is woken up.
  694. *
  695. * wake_up() has to be called after changing any variable that could
  696. * change the result of the wait condition.
  697. *
  698. * This is supposed to be called while holding the lock. The lock is
  699. * dropped before going to sleep and is reacquired afterwards.
  700. */
  701. #define wait_event_lock_irq(wq, condition, lock) \
  702. do { \
  703. if (condition) \
  704. break; \
  705. __wait_event_lock_irq(wq, condition, lock, ); \
  706. } while (0)
  707. #define __wait_event_interruptible_lock_irq(wq, condition, lock, cmd) \
  708. ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0, \
  709. spin_unlock_irq(&lock); \
  710. cmd; \
  711. schedule(); \
  712. spin_lock_irq(&lock))
  713. /**
  714. * wait_event_interruptible_lock_irq_cmd - sleep until a condition gets true.
  715. * The condition is checked under the lock. This is expected to
  716. * be called with the lock taken.
  717. * @wq: the waitqueue to wait on
  718. * @condition: a C expression for the event to wait for
  719. * @lock: a locked spinlock_t, which will be released before cmd and
  720. * schedule() and reacquired afterwards.
  721. * @cmd: a command which is invoked outside the critical section before
  722. * sleep
  723. *
  724. * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  725. * @condition evaluates to true or a signal is received. The @condition is
  726. * checked each time the waitqueue @wq is woken up.
  727. *
  728. * wake_up() has to be called after changing any variable that could
  729. * change the result of the wait condition.
  730. *
  731. * This is supposed to be called while holding the lock. The lock is
  732. * dropped before invoking the cmd and going to sleep and is reacquired
  733. * afterwards.
  734. *
  735. * The macro will return -ERESTARTSYS if it was interrupted by a signal
  736. * and 0 if @condition evaluated to true.
  737. */
  738. #define wait_event_interruptible_lock_irq_cmd(wq, condition, lock, cmd) \
  739. ({ \
  740. int __ret = 0; \
  741. if (!(condition)) \
  742. __ret = __wait_event_interruptible_lock_irq(wq, \
  743. condition, lock, cmd); \
  744. __ret; \
  745. })
  746. /**
  747. * wait_event_interruptible_lock_irq - sleep until a condition gets true.
  748. * The condition is checked under the lock. This is expected
  749. * to be called with the lock taken.
  750. * @wq: the waitqueue to wait on
  751. * @condition: a C expression for the event to wait for
  752. * @lock: a locked spinlock_t, which will be released before schedule()
  753. * and reacquired afterwards.
  754. *
  755. * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  756. * @condition evaluates to true or signal is received. The @condition is
  757. * checked each time the waitqueue @wq is woken up.
  758. *
  759. * wake_up() has to be called after changing any variable that could
  760. * change the result of the wait condition.
  761. *
  762. * This is supposed to be called while holding the lock. The lock is
  763. * dropped before going to sleep and is reacquired afterwards.
  764. *
  765. * The macro will return -ERESTARTSYS if it was interrupted by a signal
  766. * and 0 if @condition evaluated to true.
  767. */
  768. #define wait_event_interruptible_lock_irq(wq, condition, lock) \
  769. ({ \
  770. int __ret = 0; \
  771. if (!(condition)) \
  772. __ret = __wait_event_interruptible_lock_irq(wq, \
  773. condition, lock,); \
  774. __ret; \
  775. })
  776. #define __wait_event_interruptible_lock_irq_timeout(wq, condition, \
  777. lock, timeout) \
  778. ___wait_event(wq, ___wait_cond_timeout(condition), \
  779. TASK_INTERRUPTIBLE, 0, timeout, \
  780. spin_unlock_irq(&lock); \
  781. __ret = schedule_timeout(__ret); \
  782. spin_lock_irq(&lock));
  783. /**
  784. * wait_event_interruptible_lock_irq_timeout - sleep until a condition gets
  785. * true or a timeout elapses. The condition is checked under
  786. * the lock. This is expected to be called with the lock taken.
  787. * @wq: the waitqueue to wait on
  788. * @condition: a C expression for the event to wait for
  789. * @lock: a locked spinlock_t, which will be released before schedule()
  790. * and reacquired afterwards.
  791. * @timeout: timeout, in jiffies
  792. *
  793. * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  794. * @condition evaluates to true or signal is received. The @condition is
  795. * checked each time the waitqueue @wq is woken up.
  796. *
  797. * wake_up() has to be called after changing any variable that could
  798. * change the result of the wait condition.
  799. *
  800. * This is supposed to be called while holding the lock. The lock is
  801. * dropped before going to sleep and is reacquired afterwards.
  802. *
  803. * The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it
  804. * was interrupted by a signal, and the remaining jiffies otherwise
  805. * if the condition evaluated to true before the timeout elapsed.
  806. */
  807. #define wait_event_interruptible_lock_irq_timeout(wq, condition, lock, \
  808. timeout) \
  809. ({ \
  810. long __ret = timeout; \
  811. if (!___wait_cond_timeout(condition)) \
  812. __ret = __wait_event_interruptible_lock_irq_timeout( \
  813. wq, condition, lock, timeout); \
  814. __ret; \
  815. })
  816. /*
  817. * Waitqueues which are removed from the waitqueue_head at wakeup time
  818. */
  819. void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state);
  820. void prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state);
  821. long prepare_to_wait_event(wait_queue_head_t *q, wait_queue_t *wait, int state);
  822. void finish_wait(wait_queue_head_t *q, wait_queue_t *wait);
  823. void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, unsigned int mode, void *key);
  824. long wait_woken(wait_queue_t *wait, unsigned mode, long timeout);
  825. int woken_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
  826. int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
  827. int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
  828. #define DEFINE_WAIT_FUNC(name, function) \
  829. wait_queue_t name = { \
  830. .private = current, \
  831. .func = function, \
  832. .task_list = LIST_HEAD_INIT((name).task_list), \
  833. }
  834. #define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
  835. #define DEFINE_WAIT_BIT(name, word, bit) \
  836. struct wait_bit_queue name = { \
  837. .key = __WAIT_BIT_KEY_INITIALIZER(word, bit), \
  838. .wait = { \
  839. .private = current, \
  840. .func = wake_bit_function, \
  841. .task_list = \
  842. LIST_HEAD_INIT((name).wait.task_list), \
  843. }, \
  844. }
  845. #define init_wait(wait) \
  846. do { \
  847. (wait)->private = current; \
  848. (wait)->func = autoremove_wake_function; \
  849. INIT_LIST_HEAD(&(wait)->task_list); \
  850. (wait)->flags = 0; \
  851. } while (0)
  852. extern int bit_wait(struct wait_bit_key *);
  853. extern int bit_wait_io(struct wait_bit_key *);
  854. extern int bit_wait_timeout(struct wait_bit_key *);
  855. extern int bit_wait_io_timeout(struct wait_bit_key *);
  856. /**
  857. * wait_on_bit - wait for a bit to be cleared
  858. * @word: the word being waited on, a kernel virtual address
  859. * @bit: the bit of the word being waited on
  860. * @mode: the task state to sleep in
  861. *
  862. * There is a standard hashed waitqueue table for generic use. This
  863. * is the part of the hashtable's accessor API that waits on a bit.
  864. * For instance, if one were to have waiters on a bitflag, one would
  865. * call wait_on_bit() in threads waiting for the bit to clear.
  866. * One uses wait_on_bit() where one is waiting for the bit to clear,
  867. * but has no intention of setting it.
  868. * Returned value will be zero if the bit was cleared, or non-zero
  869. * if the process received a signal and the mode permitted wakeup
  870. * on that signal.
  871. */
  872. static inline int
  873. wait_on_bit(void *word, int bit, unsigned mode)
  874. {
  875. might_sleep();
  876. if (!test_bit(bit, word))
  877. return 0;
  878. return out_of_line_wait_on_bit(word, bit,
  879. bit_wait,
  880. mode);
  881. }
  882. /**
  883. * wait_on_bit_io - wait for a bit to be cleared
  884. * @word: the word being waited on, a kernel virtual address
  885. * @bit: the bit of the word being waited on
  886. * @mode: the task state to sleep in
  887. *
  888. * Use the standard hashed waitqueue table to wait for a bit
  889. * to be cleared. This is similar to wait_on_bit(), but calls
  890. * io_schedule() instead of schedule() for the actual waiting.
  891. *
  892. * Returned value will be zero if the bit was cleared, or non-zero
  893. * if the process received a signal and the mode permitted wakeup
  894. * on that signal.
  895. */
  896. static inline int
  897. wait_on_bit_io(void *word, int bit, unsigned mode)
  898. {
  899. might_sleep();
  900. if (!test_bit(bit, word))
  901. return 0;
  902. return out_of_line_wait_on_bit(word, bit,
  903. bit_wait_io,
  904. mode);
  905. }
  906. /**
  907. * wait_on_bit_timeout - wait for a bit to be cleared or a timeout elapses
  908. * @word: the word being waited on, a kernel virtual address
  909. * @bit: the bit of the word being waited on
  910. * @mode: the task state to sleep in
  911. * @timeout: timeout, in jiffies
  912. *
  913. * Use the standard hashed waitqueue table to wait for a bit
  914. * to be cleared. This is similar to wait_on_bit(), except also takes a
  915. * timeout parameter.
  916. *
  917. * Returned value will be zero if the bit was cleared before the
  918. * @timeout elapsed, or non-zero if the @timeout elapsed or process
  919. * received a signal and the mode permitted wakeup on that signal.
  920. */
  921. static inline int
  922. wait_on_bit_timeout(void *word, int bit, unsigned mode, unsigned long timeout)
  923. {
  924. might_sleep();
  925. if (!test_bit(bit, word))
  926. return 0;
  927. return out_of_line_wait_on_bit_timeout(word, bit,
  928. bit_wait_timeout,
  929. mode, timeout);
  930. }
  931. /**
  932. * wait_on_bit_action - wait for a bit to be cleared
  933. * @word: the word being waited on, a kernel virtual address
  934. * @bit: the bit of the word being waited on
  935. * @action: the function used to sleep, which may take special actions
  936. * @mode: the task state to sleep in
  937. *
  938. * Use the standard hashed waitqueue table to wait for a bit
  939. * to be cleared, and allow the waiting action to be specified.
  940. * This is like wait_on_bit() but allows fine control of how the waiting
  941. * is done.
  942. *
  943. * Returned value will be zero if the bit was cleared, or non-zero
  944. * if the process received a signal and the mode permitted wakeup
  945. * on that signal.
  946. */
  947. static inline int
  948. wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned mode)
  949. {
  950. might_sleep();
  951. if (!test_bit(bit, word))
  952. return 0;
  953. return out_of_line_wait_on_bit(word, bit, action, mode);
  954. }
  955. /**
  956. * wait_on_bit_lock - wait for a bit to be cleared, when wanting to set it
  957. * @word: the word being waited on, a kernel virtual address
  958. * @bit: the bit of the word being waited on
  959. * @mode: the task state to sleep in
  960. *
  961. * There is a standard hashed waitqueue table for generic use. This
  962. * is the part of the hashtable's accessor API that waits on a bit
  963. * when one intends to set it, for instance, trying to lock bitflags.
  964. * For instance, if one were to have waiters trying to set bitflag
  965. * and waiting for it to clear before setting it, one would call
  966. * wait_on_bit() in threads waiting to be able to set the bit.
  967. * One uses wait_on_bit_lock() where one is waiting for the bit to
  968. * clear with the intention of setting it, and when done, clearing it.
  969. *
  970. * Returns zero if the bit was (eventually) found to be clear and was
  971. * set. Returns non-zero if a signal was delivered to the process and
  972. * the @mode allows that signal to wake the process.
  973. */
  974. static inline int
  975. wait_on_bit_lock(void *word, int bit, unsigned mode)
  976. {
  977. might_sleep();
  978. if (!test_and_set_bit(bit, word))
  979. return 0;
  980. return out_of_line_wait_on_bit_lock(word, bit, bit_wait, mode);
  981. }
  982. /**
  983. * wait_on_bit_lock_io - wait for a bit to be cleared, when wanting to set it
  984. * @word: the word being waited on, a kernel virtual address
  985. * @bit: the bit of the word being waited on
  986. * @mode: the task state to sleep in
  987. *
  988. * Use the standard hashed waitqueue table to wait for a bit
  989. * to be cleared and then to atomically set it. This is similar
  990. * to wait_on_bit(), but calls io_schedule() instead of schedule()
  991. * for the actual waiting.
  992. *
  993. * Returns zero if the bit was (eventually) found to be clear and was
  994. * set. Returns non-zero if a signal was delivered to the process and
  995. * the @mode allows that signal to wake the process.
  996. */
  997. static inline int
  998. wait_on_bit_lock_io(void *word, int bit, unsigned mode)
  999. {
  1000. might_sleep();
  1001. if (!test_and_set_bit(bit, word))
  1002. return 0;
  1003. return out_of_line_wait_on_bit_lock(word, bit, bit_wait_io, mode);
  1004. }
  1005. /**
  1006. * wait_on_bit_lock_action - wait for a bit to be cleared, when wanting to set it
  1007. * @word: the word being waited on, a kernel virtual address
  1008. * @bit: the bit of the word being waited on
  1009. * @action: the function used to sleep, which may take special actions
  1010. * @mode: the task state to sleep in
  1011. *
  1012. * Use the standard hashed waitqueue table to wait for a bit
  1013. * to be cleared and then to set it, and allow the waiting action
  1014. * to be specified.
  1015. * This is like wait_on_bit() but allows fine control of how the waiting
  1016. * is done.
  1017. *
  1018. * Returns zero if the bit was (eventually) found to be clear and was
  1019. * set. Returns non-zero if a signal was delivered to the process and
  1020. * the @mode allows that signal to wake the process.
  1021. */
  1022. static inline int
  1023. wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, unsigned mode)
  1024. {
  1025. might_sleep();
  1026. if (!test_and_set_bit(bit, word))
  1027. return 0;
  1028. return out_of_line_wait_on_bit_lock(word, bit, action, mode);
  1029. }
  1030. /**
  1031. * wait_on_atomic_t - Wait for an atomic_t to become 0
  1032. * @val: The atomic value being waited on, a kernel virtual address
  1033. * @action: the function used to sleep, which may take special actions
  1034. * @mode: the task state to sleep in
  1035. *
  1036. * Wait for an atomic_t to become 0. We abuse the bit-wait waitqueue table for
  1037. * the purpose of getting a waitqueue, but we set the key to a bit number
  1038. * outside of the target 'word'.
  1039. */
  1040. static inline
  1041. int wait_on_atomic_t(atomic_t *val, int (*action)(atomic_t *), unsigned mode)
  1042. {
  1043. might_sleep();
  1044. if (atomic_read(val) == 0)
  1045. return 0;
  1046. return out_of_line_wait_on_atomic_t(val, action, mode);
  1047. }
  1048. #endif /* _LINUX_WAIT_H */