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.c for details.
11 #include <linux/wait.h>
14 * struct completion - structure used to maintain state for a "completion"
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.
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
27 wait_queue_head_t wait;
30 #define COMPLETION_INITIALIZER(work) \
31 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
33 #define COMPLETION_INITIALIZER_ONSTACK(work) \
34 ({ init_completion(&work); work; })
37 * DECLARE_COMPLETION: - declare and initialize a completion structure
38 * @work: identifier for the completion structure
40 * This macro declares and initializes a completion structure. Generally used
41 * for static declarations. You should use the _ONSTACK variant for automatic
44 #define DECLARE_COMPLETION(work) \
45 struct completion work = COMPLETION_INITIALIZER(work)
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:
53 * DECLARE_COMPLETION_ONSTACK: - declare and initialize a completion structure
54 * @work: identifier for the completion structure
56 * This macro declares and initializes a completion structure on the kernel
60 # define DECLARE_COMPLETION_ONSTACK(work) \
61 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
63 # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
67 * init_completion: - Initialize a dynamically allocated completion
68 * @x: completion structure that is to be initialized
70 * This inline function will initialize a dynamically created completion
73 static inline void init_completion(struct completion *x)
76 init_waitqueue_head(&x->wait);
79 extern void wait_for_completion(struct completion *);
80 extern int wait_for_completion_interruptible(struct completion *x);
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);
84 extern unsigned long wait_for_completion_interruptible_timeout(
85 struct completion *x, unsigned long timeout);
86 extern bool try_wait_for_completion(struct completion *x);
87 extern bool completion_done(struct completion *x);
89 extern void complete(struct completion *);
90 extern void complete_all(struct completion *);
93 * INIT_COMPLETION: - reinitialize a completion structure
94 * @x: completion structure to be reinitialized
96 * This macro should be used to reinitialize a completion structure so it can
97 * be reused. This is especially important after complete_all() is used.
99 #define INIT_COMPLETION(x) ((x).done = 0)