1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_COMPLETION_H
3 #define __LINUX_COMPLETION_H
6 * (C) Copyright 2001 Linus Torvalds
8 * Atomic wait-for-completion handler data structures.
9 * See kernel/sched/completion.c for details.
12 #include <linux/wait.h>
13 #endif /* __UBOOT__ */
16 * struct completion - structure used to maintain state for a "completion"
18 * This is the opaque structure used to maintain the state for a "completion".
19 * Completions currently use a FIFO to queue threads that have to wait for
20 * the "completion" event.
22 * See also: complete(), wait_for_completion() (and friends _timeout,
23 * _interruptible, _interruptible_timeout, and _killable), init_completion(),
24 * reinit_completion(), and macros DECLARE_COMPLETION(),
25 * DECLARE_COMPLETION_ONSTACK().
30 wait_queue_head_t wait;
31 #endif /* __UBOOT__ */
34 #define init_completion_map(x, m) __init_completion(x)
35 #define init_completion(x) __init_completion(x)
36 static inline void complete_acquire(struct completion *x) {}
37 static inline void complete_release(struct completion *x) {}
39 #define COMPLETION_INITIALIZER(work) \
40 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
42 #define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \
43 (*({ init_completion_map(&(work), &(map)); &(work); }))
45 #define COMPLETION_INITIALIZER_ONSTACK(work) \
46 (*({ init_completion(&work); &work; }))
49 * DECLARE_COMPLETION - declare and initialize a completion structure
50 * @work: identifier for the completion structure
52 * This macro declares and initializes a completion structure. Generally used
53 * for static declarations. You should use the _ONSTACK variant for automatic
56 #define DECLARE_COMPLETION(work) \
57 struct completion work = COMPLETION_INITIALIZER(work)
60 * Lockdep needs to run a non-constant initializer for on-stack
61 * completions - so we use the _ONSTACK() variant for those that
62 * are on the kernel stack:
65 * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure
66 * @work: identifier for the completion structure
68 * This macro declares and initializes a completion structure on the kernel
72 # define DECLARE_COMPLETION_ONSTACK(work) \
73 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
74 # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) \
75 struct completion work = COMPLETION_INITIALIZER_ONSTACK_MAP(work, map)
77 # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
78 # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) DECLARE_COMPLETION(work)
82 * init_completion - Initialize a dynamically allocated completion
83 * @x: pointer to completion structure that is to be initialized
85 * This inline function will initialize a dynamically created completion
88 static inline void __init_completion(struct completion *x)
92 init_waitqueue_head(&x->wait);
93 #endif /* __UBOOT__ */
97 * reinit_completion - reinitialize a completion structure
98 * @x: pointer to completion structure that is to be reinitialized
100 * This inline function should be used to reinitialize a completion structure so it can
101 * be reused. This is especially important after complete_all() is used.
103 static inline void reinit_completion(struct completion *x)
109 extern void wait_for_completion(struct completion *);
110 extern void wait_for_completion_io(struct completion *);
111 extern int wait_for_completion_interruptible(struct completion *x);
112 extern int wait_for_completion_killable(struct completion *x);
113 extern unsigned long wait_for_completion_timeout(struct completion *x,
114 unsigned long timeout);
115 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
116 unsigned long timeout);
117 extern long wait_for_completion_interruptible_timeout(
118 struct completion *x, unsigned long timeout);
119 extern long wait_for_completion_killable_timeout(
120 struct completion *x, unsigned long timeout);
121 extern bool try_wait_for_completion(struct completion *x);
122 extern bool completion_done(struct completion *x);
124 extern void complete(struct completion *);
125 extern void complete_all(struct completion *);
127 #else /* __UBOOT __ */
129 #define wait_for_completion(x) do {} while (0)
130 #define wait_for_completion_io(x) do {} while (0)
132 inline int wait_for_completion_interruptible(struct completion *x)
136 inline int wait_for_completion_killable(struct completion *x)
140 inline unsigned long wait_for_completion_timeout(struct completion *x,
141 unsigned long timeout)
145 inline unsigned long wait_for_completion_io_timeout(struct completion *x,
146 unsigned long timeout)
150 inline long wait_for_completion_interruptible_timeout(struct completion *x,
151 unsigned long timeout)
155 inline long wait_for_completion_killable_timeout(struct completion *x,
156 unsigned long timeout)
160 inline bool try_wait_for_completion(struct completion *x)
164 inline bool completion_done(struct completion *x)
169 #define complete(x) do {} while (0)
170 #define complete_all(x) do {} while (0)
171 #endif /* __UBOOT__ */