Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
completion.h
Go to the documentation of this file.
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 /*
14  * struct completion - structure used to maintain state for a "completion"
15  *
16  * This is the opaque structure used to maintain the state for a "completion".
17  * Completions currently use a FIFO to queue threads that have to wait for
18  * the "completion" event.
19  *
20  * See also: complete(), wait_for_completion() (and friends _timeout,
21  * _interruptible, _interruptible_timeout, and _killable), init_completion(),
22  * and macros DECLARE_COMPLETION(), DECLARE_COMPLETION_ONSTACK(), and
23  * INIT_COMPLETION().
24  */
25 struct completion {
26  unsigned int done;
28 };
29 
30 #define COMPLETION_INITIALIZER(work) \
31  { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
32 
33 #define COMPLETION_INITIALIZER_ONSTACK(work) \
34  ({ init_completion(&work); work; })
35 
44 #define DECLARE_COMPLETION(work) \
45  struct completion work = COMPLETION_INITIALIZER(work)
46 
47 /*
48  * Lockdep needs to run a non-constant initializer for on-stack
49  * completions - so we use the _ONSTACK() variant for those that
50  * are on the kernel stack:
51  */
59 #ifdef CONFIG_LOCKDEP
60 # define DECLARE_COMPLETION_ONSTACK(work) \
61  struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
62 #else
63 # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
64 #endif
65 
73 static inline void init_completion(struct completion *x)
74 {
75  x->done = 0;
77 }
78 
79 extern void wait_for_completion(struct completion *);
81 extern int wait_for_completion_killable(struct completion *x);
82 extern unsigned long wait_for_completion_timeout(struct completion *x,
83  unsigned long timeout);
85  struct completion *x, unsigned long timeout);
87  struct completion *x, unsigned long timeout);
88 extern bool try_wait_for_completion(struct completion *x);
89 extern bool completion_done(struct completion *x);
90 
91 extern void complete(struct completion *);
92 extern void complete_all(struct completion *);
93 
101 #define INIT_COMPLETION(x) ((x).done = 0)
102 
103 
104 #endif