Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_COMPLETION_H |
| 2 | #define __LINUX_COMPLETION_H |
| 3 | |
| 4 | /* |
| 5 | * (C) Copyright 2001 Linus Torvalds |
| 6 | * |
| 7 | * Atomic wait-for-completion handler data structures. |
| 8 | * See kernel/sched.c for details. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/wait.h> |
| 12 | |
| 13 | struct completion { |
| 14 | unsigned int done; |
| 15 | wait_queue_head_t wait; |
| 16 | }; |
| 17 | |
| 18 | #define COMPLETION_INITIALIZER(work) \ |
| 19 | { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) } |
| 20 | |
Ingo Molnar | f86bf9b | 2006-07-10 04:44:05 -0700 | [diff] [blame] | 21 | #define COMPLETION_INITIALIZER_ONSTACK(work) \ |
| 22 | ({ init_completion(&work); work; }) |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #define DECLARE_COMPLETION(work) \ |
| 25 | struct completion work = COMPLETION_INITIALIZER(work) |
| 26 | |
Ingo Molnar | 8b3db9c | 2006-07-03 00:24:28 -0700 | [diff] [blame] | 27 | /* |
| 28 | * Lockdep needs to run a non-constant initializer for on-stack |
| 29 | * completions - so we use the _ONSTACK() variant for those that |
| 30 | * are on the kernel stack: |
| 31 | */ |
| 32 | #ifdef CONFIG_LOCKDEP |
| 33 | # define DECLARE_COMPLETION_ONSTACK(work) \ |
Ingo Molnar | f86bf9b | 2006-07-10 04:44:05 -0700 | [diff] [blame] | 34 | struct completion work = COMPLETION_INITIALIZER_ONSTACK(work) |
Ingo Molnar | 8b3db9c | 2006-07-03 00:24:28 -0700 | [diff] [blame] | 35 | #else |
| 36 | # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work) |
| 37 | #endif |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | static inline void init_completion(struct completion *x) |
| 40 | { |
| 41 | x->done = 0; |
| 42 | init_waitqueue_head(&x->wait); |
| 43 | } |
| 44 | |
Ingo Molnar | b15136e | 2007-10-24 18:23:48 +0200 | [diff] [blame] | 45 | extern void wait_for_completion(struct completion *); |
| 46 | extern int wait_for_completion_interruptible(struct completion *x); |
Matthew Wilcox | 009e577 | 2007-12-06 12:29:54 -0500 | [diff] [blame] | 47 | extern int wait_for_completion_killable(struct completion *x); |
Ingo Molnar | b15136e | 2007-10-24 18:23:48 +0200 | [diff] [blame] | 48 | extern unsigned long wait_for_completion_timeout(struct completion *x, |
| 49 | unsigned long timeout); |
| 50 | extern unsigned long wait_for_completion_interruptible_timeout( |
| 51 | struct completion *x, unsigned long timeout); |
Dave Chinner | be4de35 | 2008-08-15 00:40:44 -0700 | [diff] [blame] | 52 | extern bool try_wait_for_completion(struct completion *x); |
| 53 | extern bool completion_done(struct completion *x); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Ingo Molnar | b15136e | 2007-10-24 18:23:48 +0200 | [diff] [blame] | 55 | extern void complete(struct completion *); |
| 56 | extern void complete_all(struct completion *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | #define INIT_COMPLETION(x) ((x).done = 0) |
| 59 | |
David Chinner | 39d2f1a | 2008-08-13 16:40:43 +1000 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #endif |