diff options
Diffstat (limited to 'include/linux/wait.h')
-rw-r--r-- | include/linux/wait.h | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/include/linux/wait.h b/include/linux/wait.h index e4a8eb9312ea..2232ed16635a 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h | |||
@@ -13,9 +13,12 @@ typedef struct __wait_queue wait_queue_t; | |||
13 | typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key); | 13 | typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key); |
14 | int default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key); | 14 | int default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key); |
15 | 15 | ||
16 | /* __wait_queue::flags */ | ||
17 | #define WQ_FLAG_EXCLUSIVE 0x01 | ||
18 | #define WQ_FLAG_WOKEN 0x02 | ||
19 | |||
16 | struct __wait_queue { | 20 | struct __wait_queue { |
17 | unsigned int flags; | 21 | unsigned int flags; |
18 | #define WQ_FLAG_EXCLUSIVE 0x01 | ||
19 | void *private; | 22 | void *private; |
20 | wait_queue_func_t func; | 23 | wait_queue_func_t func; |
21 | struct list_head task_list; | 24 | struct list_head task_list; |
@@ -258,11 +261,37 @@ __out: __ret; \ | |||
258 | */ | 261 | */ |
259 | #define wait_event(wq, condition) \ | 262 | #define wait_event(wq, condition) \ |
260 | do { \ | 263 | do { \ |
264 | might_sleep(); \ | ||
261 | if (condition) \ | 265 | if (condition) \ |
262 | break; \ | 266 | break; \ |
263 | __wait_event(wq, condition); \ | 267 | __wait_event(wq, condition); \ |
264 | } while (0) | 268 | } while (0) |
265 | 269 | ||
270 | #define __wait_event_freezable(wq, condition) \ | ||
271 | ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0, \ | ||
272 | schedule(); try_to_freeze()) | ||
273 | |||
274 | /** | ||
275 | * wait_event - sleep (or freeze) until a condition gets true | ||
276 | * @wq: the waitqueue to wait on | ||
277 | * @condition: a C expression for the event to wait for | ||
278 | * | ||
279 | * The process is put to sleep (TASK_INTERRUPTIBLE -- so as not to contribute | ||
280 | * to system load) until the @condition evaluates to true. The | ||
281 | * @condition is checked each time the waitqueue @wq is woken up. | ||
282 | * | ||
283 | * wake_up() has to be called after changing any variable that could | ||
284 | * change the result of the wait condition. | ||
285 | */ | ||
286 | #define wait_event_freezable(wq, condition) \ | ||
287 | ({ \ | ||
288 | int __ret = 0; \ | ||
289 | might_sleep(); \ | ||
290 | if (!(condition)) \ | ||
291 | __ret = __wait_event_freezable(wq, condition); \ | ||
292 | __ret; \ | ||
293 | }) | ||
294 | |||
266 | #define __wait_event_timeout(wq, condition, timeout) \ | 295 | #define __wait_event_timeout(wq, condition, timeout) \ |
267 | ___wait_event(wq, ___wait_cond_timeout(condition), \ | 296 | ___wait_event(wq, ___wait_cond_timeout(condition), \ |
268 | TASK_UNINTERRUPTIBLE, 0, timeout, \ | 297 | TASK_UNINTERRUPTIBLE, 0, timeout, \ |
@@ -290,11 +319,30 @@ do { \ | |||
290 | #define wait_event_timeout(wq, condition, timeout) \ | 319 | #define wait_event_timeout(wq, condition, timeout) \ |
291 | ({ \ | 320 | ({ \ |
292 | long __ret = timeout; \ | 321 | long __ret = timeout; \ |
322 | might_sleep(); \ | ||
293 | if (!___wait_cond_timeout(condition)) \ | 323 | if (!___wait_cond_timeout(condition)) \ |
294 | __ret = __wait_event_timeout(wq, condition, timeout); \ | 324 | __ret = __wait_event_timeout(wq, condition, timeout); \ |
295 | __ret; \ | 325 | __ret; \ |
296 | }) | 326 | }) |
297 | 327 | ||
328 | #define __wait_event_freezable_timeout(wq, condition, timeout) \ | ||
329 | ___wait_event(wq, ___wait_cond_timeout(condition), \ | ||
330 | TASK_INTERRUPTIBLE, 0, timeout, \ | ||
331 | __ret = schedule_timeout(__ret); try_to_freeze()) | ||
332 | |||
333 | /* | ||
334 | * like wait_event_timeout() -- except it uses TASK_INTERRUPTIBLE to avoid | ||
335 | * increasing load and is freezable. | ||
336 | */ | ||
337 | #define wait_event_freezable_timeout(wq, condition, timeout) \ | ||
338 | ({ \ | ||
339 | long __ret = timeout; \ | ||
340 | might_sleep(); \ | ||
341 | if (!___wait_cond_timeout(condition)) \ | ||
342 | __ret = __wait_event_freezable_timeout(wq, condition, timeout); \ | ||
343 | __ret; \ | ||
344 | }) | ||
345 | |||
298 | #define __wait_event_cmd(wq, condition, cmd1, cmd2) \ | 346 | #define __wait_event_cmd(wq, condition, cmd1, cmd2) \ |
299 | (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \ | 347 | (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \ |
300 | cmd1; schedule(); cmd2) | 348 | cmd1; schedule(); cmd2) |
@@ -315,6 +363,7 @@ do { \ | |||
315 | */ | 363 | */ |
316 | #define wait_event_cmd(wq, condition, cmd1, cmd2) \ | 364 | #define wait_event_cmd(wq, condition, cmd1, cmd2) \ |
317 | do { \ | 365 | do { \ |
366 | might_sleep(); \ | ||
318 | if (condition) \ | 367 | if (condition) \ |
319 | break; \ | 368 | break; \ |
320 | __wait_event_cmd(wq, condition, cmd1, cmd2); \ | 369 | __wait_event_cmd(wq, condition, cmd1, cmd2); \ |
@@ -342,6 +391,7 @@ do { \ | |||
342 | #define wait_event_interruptible(wq, condition) \ | 391 | #define wait_event_interruptible(wq, condition) \ |
343 | ({ \ | 392 | ({ \ |
344 | int __ret = 0; \ | 393 | int __ret = 0; \ |
394 | might_sleep(); \ | ||
345 | if (!(condition)) \ | 395 | if (!(condition)) \ |
346 | __ret = __wait_event_interruptible(wq, condition); \ | 396 | __ret = __wait_event_interruptible(wq, condition); \ |
347 | __ret; \ | 397 | __ret; \ |
@@ -375,6 +425,7 @@ do { \ | |||
375 | #define wait_event_interruptible_timeout(wq, condition, timeout) \ | 425 | #define wait_event_interruptible_timeout(wq, condition, timeout) \ |
376 | ({ \ | 426 | ({ \ |
377 | long __ret = timeout; \ | 427 | long __ret = timeout; \ |
428 | might_sleep(); \ | ||
378 | if (!___wait_cond_timeout(condition)) \ | 429 | if (!___wait_cond_timeout(condition)) \ |
379 | __ret = __wait_event_interruptible_timeout(wq, \ | 430 | __ret = __wait_event_interruptible_timeout(wq, \ |
380 | condition, timeout); \ | 431 | condition, timeout); \ |
@@ -425,6 +476,7 @@ do { \ | |||
425 | #define wait_event_hrtimeout(wq, condition, timeout) \ | 476 | #define wait_event_hrtimeout(wq, condition, timeout) \ |
426 | ({ \ | 477 | ({ \ |
427 | int __ret = 0; \ | 478 | int __ret = 0; \ |
479 | might_sleep(); \ | ||
428 | if (!(condition)) \ | 480 | if (!(condition)) \ |
429 | __ret = __wait_event_hrtimeout(wq, condition, timeout, \ | 481 | __ret = __wait_event_hrtimeout(wq, condition, timeout, \ |
430 | TASK_UNINTERRUPTIBLE); \ | 482 | TASK_UNINTERRUPTIBLE); \ |
@@ -450,6 +502,7 @@ do { \ | |||
450 | #define wait_event_interruptible_hrtimeout(wq, condition, timeout) \ | 502 | #define wait_event_interruptible_hrtimeout(wq, condition, timeout) \ |
451 | ({ \ | 503 | ({ \ |
452 | long __ret = 0; \ | 504 | long __ret = 0; \ |
505 | might_sleep(); \ | ||
453 | if (!(condition)) \ | 506 | if (!(condition)) \ |
454 | __ret = __wait_event_hrtimeout(wq, condition, timeout, \ | 507 | __ret = __wait_event_hrtimeout(wq, condition, timeout, \ |
455 | TASK_INTERRUPTIBLE); \ | 508 | TASK_INTERRUPTIBLE); \ |
@@ -463,12 +516,27 @@ do { \ | |||
463 | #define wait_event_interruptible_exclusive(wq, condition) \ | 516 | #define wait_event_interruptible_exclusive(wq, condition) \ |
464 | ({ \ | 517 | ({ \ |
465 | int __ret = 0; \ | 518 | int __ret = 0; \ |
519 | might_sleep(); \ | ||
466 | if (!(condition)) \ | 520 | if (!(condition)) \ |
467 | __ret = __wait_event_interruptible_exclusive(wq, condition);\ | 521 | __ret = __wait_event_interruptible_exclusive(wq, condition);\ |
468 | __ret; \ | 522 | __ret; \ |
469 | }) | 523 | }) |
470 | 524 | ||
471 | 525 | ||
526 | #define __wait_event_freezable_exclusive(wq, condition) \ | ||
527 | ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, 0, \ | ||
528 | schedule(); try_to_freeze()) | ||
529 | |||
530 | #define wait_event_freezable_exclusive(wq, condition) \ | ||
531 | ({ \ | ||
532 | int __ret = 0; \ | ||
533 | might_sleep(); \ | ||
534 | if (!(condition)) \ | ||
535 | __ret = __wait_event_freezable_exclusive(wq, condition);\ | ||
536 | __ret; \ | ||
537 | }) | ||
538 | |||
539 | |||
472 | #define __wait_event_interruptible_locked(wq, condition, exclusive, irq) \ | 540 | #define __wait_event_interruptible_locked(wq, condition, exclusive, irq) \ |
473 | ({ \ | 541 | ({ \ |
474 | int __ret = 0; \ | 542 | int __ret = 0; \ |
@@ -637,6 +705,7 @@ do { \ | |||
637 | #define wait_event_killable(wq, condition) \ | 705 | #define wait_event_killable(wq, condition) \ |
638 | ({ \ | 706 | ({ \ |
639 | int __ret = 0; \ | 707 | int __ret = 0; \ |
708 | might_sleep(); \ | ||
640 | if (!(condition)) \ | 709 | if (!(condition)) \ |
641 | __ret = __wait_event_killable(wq, condition); \ | 710 | __ret = __wait_event_killable(wq, condition); \ |
642 | __ret; \ | 711 | __ret; \ |
@@ -830,6 +899,8 @@ void prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int sta | |||
830 | long prepare_to_wait_event(wait_queue_head_t *q, wait_queue_t *wait, int state); | 899 | long prepare_to_wait_event(wait_queue_head_t *q, wait_queue_t *wait, int state); |
831 | void finish_wait(wait_queue_head_t *q, wait_queue_t *wait); | 900 | void finish_wait(wait_queue_head_t *q, wait_queue_t *wait); |
832 | void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, unsigned int mode, void *key); | 901 | void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, unsigned int mode, void *key); |
902 | long wait_woken(wait_queue_t *wait, unsigned mode, long timeout); | ||
903 | int woken_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key); | ||
833 | int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key); | 904 | int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key); |
834 | int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key); | 905 | int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key); |
835 | 906 | ||
@@ -886,6 +957,7 @@ extern int bit_wait_io_timeout(struct wait_bit_key *); | |||
886 | static inline int | 957 | static inline int |
887 | wait_on_bit(void *word, int bit, unsigned mode) | 958 | wait_on_bit(void *word, int bit, unsigned mode) |
888 | { | 959 | { |
960 | might_sleep(); | ||
889 | if (!test_bit(bit, word)) | 961 | if (!test_bit(bit, word)) |
890 | return 0; | 962 | return 0; |
891 | return out_of_line_wait_on_bit(word, bit, | 963 | return out_of_line_wait_on_bit(word, bit, |
@@ -910,6 +982,7 @@ wait_on_bit(void *word, int bit, unsigned mode) | |||
910 | static inline int | 982 | static inline int |
911 | wait_on_bit_io(void *word, int bit, unsigned mode) | 983 | wait_on_bit_io(void *word, int bit, unsigned mode) |
912 | { | 984 | { |
985 | might_sleep(); | ||
913 | if (!test_bit(bit, word)) | 986 | if (!test_bit(bit, word)) |
914 | return 0; | 987 | return 0; |
915 | return out_of_line_wait_on_bit(word, bit, | 988 | return out_of_line_wait_on_bit(word, bit, |
@@ -936,6 +1009,7 @@ wait_on_bit_io(void *word, int bit, unsigned mode) | |||
936 | static inline int | 1009 | static inline int |
937 | wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned mode) | 1010 | wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned mode) |
938 | { | 1011 | { |
1012 | might_sleep(); | ||
939 | if (!test_bit(bit, word)) | 1013 | if (!test_bit(bit, word)) |
940 | return 0; | 1014 | return 0; |
941 | return out_of_line_wait_on_bit(word, bit, action, mode); | 1015 | return out_of_line_wait_on_bit(word, bit, action, mode); |
@@ -963,6 +1037,7 @@ wait_on_bit_action(void *word, int bit, wait_bit_action_f *action, unsigned mode | |||
963 | static inline int | 1037 | static inline int |
964 | wait_on_bit_lock(void *word, int bit, unsigned mode) | 1038 | wait_on_bit_lock(void *word, int bit, unsigned mode) |
965 | { | 1039 | { |
1040 | might_sleep(); | ||
966 | if (!test_and_set_bit(bit, word)) | 1041 | if (!test_and_set_bit(bit, word)) |
967 | return 0; | 1042 | return 0; |
968 | return out_of_line_wait_on_bit_lock(word, bit, bit_wait, mode); | 1043 | return out_of_line_wait_on_bit_lock(word, bit, bit_wait, mode); |
@@ -986,6 +1061,7 @@ wait_on_bit_lock(void *word, int bit, unsigned mode) | |||
986 | static inline int | 1061 | static inline int |
987 | wait_on_bit_lock_io(void *word, int bit, unsigned mode) | 1062 | wait_on_bit_lock_io(void *word, int bit, unsigned mode) |
988 | { | 1063 | { |
1064 | might_sleep(); | ||
989 | if (!test_and_set_bit(bit, word)) | 1065 | if (!test_and_set_bit(bit, word)) |
990 | return 0; | 1066 | return 0; |
991 | return out_of_line_wait_on_bit_lock(word, bit, bit_wait_io, mode); | 1067 | return out_of_line_wait_on_bit_lock(word, bit, bit_wait_io, mode); |
@@ -1011,6 +1087,7 @@ wait_on_bit_lock_io(void *word, int bit, unsigned mode) | |||
1011 | static inline int | 1087 | static inline int |
1012 | wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, unsigned mode) | 1088 | wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, unsigned mode) |
1013 | { | 1089 | { |
1090 | might_sleep(); | ||
1014 | if (!test_and_set_bit(bit, word)) | 1091 | if (!test_and_set_bit(bit, word)) |
1015 | return 0; | 1092 | return 0; |
1016 | return out_of_line_wait_on_bit_lock(word, bit, action, mode); | 1093 | return out_of_line_wait_on_bit_lock(word, bit, action, mode); |
@@ -1029,6 +1106,7 @@ wait_on_bit_lock_action(void *word, int bit, wait_bit_action_f *action, unsigned | |||
1029 | static inline | 1106 | static inline |
1030 | int wait_on_atomic_t(atomic_t *val, int (*action)(atomic_t *), unsigned mode) | 1107 | int wait_on_atomic_t(atomic_t *val, int (*action)(atomic_t *), unsigned mode) |
1031 | { | 1108 | { |
1109 | might_sleep(); | ||
1032 | if (atomic_read(val) == 0) | 1110 | if (atomic_read(val) == 0) |
1033 | return 0; | 1111 | return 0; |
1034 | return out_of_line_wait_on_atomic_t(val, action, mode); | 1112 | return out_of_line_wait_on_atomic_t(val, action, mode); |