1 #ifndef __LINUX_COMPLETION_H
2 #define __LINUX_COMPLETION_H
5 * (C) Copyright 2001 Linus Torvalds
7 * Atomic wait-for-completion handler data structures.
8 * See kernel/sched/completion.c for details.
10 #include <linux/wait-simple.h>
13 * struct completion - structure used to maintain state for a "completion"
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.
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().
26 struct swait_head wait;
29 #define COMPLETION_INITIALIZER(work) \
30 { 0, SWAIT_HEAD_INITIALIZER((work).wait) }
32 #define COMPLETION_INITIALIZER_ONSTACK(work) \
33 ({ init_completion(&work); work; })
36 * DECLARE_COMPLETION - declare and initialize a completion structure
37 * @work: identifier for the completion structure
39 * This macro declares and initializes a completion structure. Generally used
40 * for static declarations. You should use the _ONSTACK variant for automatic
43 #define DECLARE_COMPLETION(work) \
44 struct completion work = COMPLETION_INITIALIZER(work)
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:
52 * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure
53 * @work: identifier for the completion structure
55 * This macro declares and initializes a completion structure on the kernel
59 # define DECLARE_COMPLETION_ONSTACK(work) \
60 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
62 # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
66 * init_completion - Initialize a dynamically allocated completion
67 * @x: pointer to completion structure that is to be initialized
69 * This inline function will initialize a dynamically created completion
72 static inline void init_completion(struct completion *x)
75 init_swait_head(&x->wait);
79 * reinit_completion - reinitialize a completion structure
80 * @x: pointer to completion structure that is to be reinitialized
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.
85 static inline void reinit_completion(struct completion *x)
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);
105 extern void complete(struct completion *);
106 extern void complete_all(struct completion *);