Philippe Reynes | 5db365d | 2019-03-15 15:14:35 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef __LINUX_COMPLETION_H |
| 3 | #define __LINUX_COMPLETION_H |
| 4 | |
| 5 | /* |
| 6 | * (C) Copyright 2001 Linus Torvalds |
| 7 | * |
| 8 | * Atomic wait-for-completion handler data structures. |
| 9 | * See kernel/sched/completion.c for details. |
| 10 | */ |
| 11 | #ifndef __UBOOT__ |
| 12 | #include <linux/wait.h> |
| 13 | #endif /* __UBOOT__ */ |
| 14 | |
| 15 | /* |
| 16 | * struct completion - structure used to maintain state for a "completion" |
| 17 | * |
| 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. |
| 21 | * |
| 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(). |
| 26 | */ |
| 27 | struct completion { |
| 28 | unsigned int done; |
| 29 | #ifndef __UBOOT__ |
| 30 | wait_queue_head_t wait; |
| 31 | #endif /* __UBOOT__ */ |
| 32 | }; |
| 33 | |
| 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) {} |
| 38 | |
| 39 | #define COMPLETION_INITIALIZER(work) \ |
| 40 | { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) } |
| 41 | |
| 42 | #define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \ |
| 43 | (*({ init_completion_map(&(work), &(map)); &(work); })) |
| 44 | |
| 45 | #define COMPLETION_INITIALIZER_ONSTACK(work) \ |
| 46 | (*({ init_completion(&work); &work; })) |
| 47 | |
| 48 | /** |
| 49 | * DECLARE_COMPLETION - declare and initialize a completion structure |
| 50 | * @work: identifier for the completion structure |
| 51 | * |
| 52 | * This macro declares and initializes a completion structure. Generally used |
| 53 | * for static declarations. You should use the _ONSTACK variant for automatic |
| 54 | * variables. |
| 55 | */ |
| 56 | #define DECLARE_COMPLETION(work) \ |
| 57 | struct completion work = COMPLETION_INITIALIZER(work) |
| 58 | |
| 59 | /* |
| 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: |
| 63 | */ |
| 64 | /** |
| 65 | * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure |
| 66 | * @work: identifier for the completion structure |
| 67 | * |
| 68 | * This macro declares and initializes a completion structure on the kernel |
| 69 | * stack. |
| 70 | */ |
| 71 | #ifdef CONFIG_LOCKDEP |
| 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) |
| 76 | #else |
| 77 | # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work) |
| 78 | # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) DECLARE_COMPLETION(work) |
| 79 | #endif |
| 80 | |
| 81 | /** |
| 82 | * init_completion - Initialize a dynamically allocated completion |
| 83 | * @x: pointer to completion structure that is to be initialized |
| 84 | * |
| 85 | * This inline function will initialize a dynamically created completion |
| 86 | * structure. |
| 87 | */ |
| 88 | static inline void __init_completion(struct completion *x) |
| 89 | { |
| 90 | x->done = 0; |
| 91 | #ifndef __UBOOT__ |
| 92 | init_waitqueue_head(&x->wait); |
| 93 | #endif /* __UBOOT__ */ |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * reinit_completion - reinitialize a completion structure |
| 98 | * @x: pointer to completion structure that is to be reinitialized |
| 99 | * |
| 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. |
| 102 | */ |
| 103 | static inline void reinit_completion(struct completion *x) |
| 104 | { |
| 105 | x->done = 0; |
| 106 | } |
| 107 | |
| 108 | #ifndef __UBOOT__ |
| 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); |
| 123 | |
| 124 | extern void complete(struct completion *); |
| 125 | extern void complete_all(struct completion *); |
| 126 | |
| 127 | #else /* __UBOOT __ */ |
| 128 | |
| 129 | #define wait_for_completion(x) do {} while (0) |
| 130 | #define wait_for_completion_io(x) do {} while (0) |
| 131 | |
| 132 | inline int wait_for_completion_interruptible(struct completion *x) |
| 133 | { |
| 134 | return 1; |
| 135 | } |
| 136 | inline int wait_for_completion_killable(struct completion *x) |
| 137 | { |
| 138 | return 1; |
| 139 | } |
| 140 | inline unsigned long wait_for_completion_timeout(struct completion *x, |
| 141 | unsigned long timeout) |
| 142 | { |
| 143 | return 1; |
| 144 | } |
| 145 | inline unsigned long wait_for_completion_io_timeout(struct completion *x, |
| 146 | unsigned long timeout) |
| 147 | { |
| 148 | return 1; |
| 149 | } |
| 150 | inline long wait_for_completion_interruptible_timeout(struct completion *x, |
| 151 | unsigned long timeout) |
| 152 | { |
| 153 | return 1; |
| 154 | } |
| 155 | inline long wait_for_completion_killable_timeout(struct completion *x, |
| 156 | unsigned long timeout) |
| 157 | { |
| 158 | return 1; |
| 159 | } |
| 160 | inline bool try_wait_for_completion(struct completion *x) |
| 161 | { |
| 162 | return 1; |
| 163 | } |
| 164 | inline bool completion_done(struct completion *x) |
| 165 | { |
| 166 | return 1; |
| 167 | } |
| 168 | |
| 169 | #define complete(x) do {} while (0) |
| 170 | #define complete_all(x) do {} while (0) |
| 171 | #endif /* __UBOOT__ */ |
| 172 | |
| 173 | #endif |