Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / include / linux / completion.h
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/completion.c for details.
9  */
10 #include <linux/wait-simple.h>
11
12 /*
13  * struct completion - structure used to maintain state for a "completion"
14  *
15  * This is the opaque structure used to maintain the state for a "completion".
16  * Completions currently use a FIFO to queue threads that have to wait for
17  * the "completion" event.
18  *
19  * See also:  complete(), wait_for_completion() (and friends _timeout,
20  * _interruptible, _interruptible_timeout, and _killable), init_completion(),
21  * reinit_completion(), and macros DECLARE_COMPLETION(),
22  * DECLARE_COMPLETION_ONSTACK().
23  */
24 struct completion {
25         unsigned int done;
26         struct swait_head wait;
27 };
28
29 #define COMPLETION_INITIALIZER(work) \
30         { 0, SWAIT_HEAD_INITIALIZER((work).wait) }
31
32 #define COMPLETION_INITIALIZER_ONSTACK(work) \
33         ({ init_completion(&work); work; })
34
35 /**
36  * DECLARE_COMPLETION - declare and initialize a completion structure
37  * @work:  identifier for the completion structure
38  *
39  * This macro declares and initializes a completion structure. Generally used
40  * for static declarations. You should use the _ONSTACK variant for automatic
41  * variables.
42  */
43 #define DECLARE_COMPLETION(work) \
44         struct completion work = COMPLETION_INITIALIZER(work)
45
46 /*
47  * Lockdep needs to run a non-constant initializer for on-stack
48  * completions - so we use the _ONSTACK() variant for those that
49  * are on the kernel stack:
50  */
51 /**
52  * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure
53  * @work:  identifier for the completion structure
54  *
55  * This macro declares and initializes a completion structure on the kernel
56  * stack.
57  */
58 #ifdef CONFIG_LOCKDEP
59 # define DECLARE_COMPLETION_ONSTACK(work) \
60         struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
61 #else
62 # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
63 #endif
64
65 /**
66  * init_completion - Initialize a dynamically allocated completion
67  * @x:  pointer to completion structure that is to be initialized
68  *
69  * This inline function will initialize a dynamically created completion
70  * structure.
71  */
72 static inline void init_completion(struct completion *x)
73 {
74         x->done = 0;
75         init_swait_head(&x->wait);
76 }
77
78 /**
79  * reinit_completion - reinitialize a completion structure
80  * @x:  pointer to completion structure that is to be reinitialized
81  *
82  * This inline function should be used to reinitialize a completion structure so it can
83  * be reused. This is especially important after complete_all() is used.
84  */
85 static inline void reinit_completion(struct completion *x)
86 {
87         x->done = 0;
88 }
89
90 extern void wait_for_completion(struct completion *);
91 extern void wait_for_completion_io(struct completion *);
92 extern int wait_for_completion_interruptible(struct completion *x);
93 extern int wait_for_completion_killable(struct completion *x);
94 extern unsigned long wait_for_completion_timeout(struct completion *x,
95                                                    unsigned long timeout);
96 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
97                                                     unsigned long timeout);
98 extern long wait_for_completion_interruptible_timeout(
99         struct completion *x, unsigned long timeout);
100 extern long wait_for_completion_killable_timeout(
101         struct completion *x, unsigned long timeout);
102 extern bool try_wait_for_completion(struct completion *x);
103 extern bool completion_done(struct completion *x);
104
105 extern void complete(struct completion *);
106 extern void complete_all(struct completion *);
107
108 #endif