]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
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. | |
b8a21626 | 9 | * See kernel/sched/completion.c for details. |
1da177e4 LT |
10 | */ |
11 | ||
a5c6234e | 12 | #include <linux/swait.h> |
1da177e4 | 13 | |
ee2f154a | 14 | /* |
65eb3dc6 KD |
15 | * struct completion - structure used to maintain state for a "completion" |
16 | * | |
17 | * This is the opaque structure used to maintain the state for a "completion". | |
18 | * Completions currently use a FIFO to queue threads that have to wait for | |
19 | * the "completion" event. | |
20 | * | |
21 | * See also: complete(), wait_for_completion() (and friends _timeout, | |
22 | * _interruptible, _interruptible_timeout, and _killable), init_completion(), | |
c32f74ab WS |
23 | * reinit_completion(), and macros DECLARE_COMPLETION(), |
24 | * DECLARE_COMPLETION_ONSTACK(). | |
65eb3dc6 | 25 | */ |
1da177e4 LT |
26 | struct completion { |
27 | unsigned int done; | |
a5c6234e | 28 | struct swait_queue_head wait; |
1da177e4 LT |
29 | }; |
30 | ||
b6498aad | 31 | #define init_completion_map(x, m) init_completion(x) |
cd8084f9 BP |
32 | static inline void complete_acquire(struct completion *x) {} |
33 | static inline void complete_release(struct completion *x) {} | |
cd8084f9 | 34 | |
1da177e4 | 35 | #define COMPLETION_INITIALIZER(work) \ |
a5c6234e | 36 | { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait) } |
1da177e4 | 37 | |
a7967bc3 BP |
38 | #define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \ |
39 | (*({ init_completion_map(&(work), &(map)); &(work); })) | |
40 | ||
f86bf9b7 | 41 | #define COMPLETION_INITIALIZER_ONSTACK(work) \ |
ec81048c | 42 | (*({ init_completion(&work); &work; })) |
f86bf9b7 | 43 | |
65eb3dc6 | 44 | /** |
ee2f154a | 45 | * DECLARE_COMPLETION - declare and initialize a completion structure |
65eb3dc6 KD |
46 | * @work: identifier for the completion structure |
47 | * | |
48 | * This macro declares and initializes a completion structure. Generally used | |
49 | * for static declarations. You should use the _ONSTACK variant for automatic | |
50 | * variables. | |
51 | */ | |
1da177e4 LT |
52 | #define DECLARE_COMPLETION(work) \ |
53 | struct completion work = COMPLETION_INITIALIZER(work) | |
54 | ||
8b3db9c5 IM |
55 | /* |
56 | * Lockdep needs to run a non-constant initializer for on-stack | |
57 | * completions - so we use the _ONSTACK() variant for those that | |
58 | * are on the kernel stack: | |
59 | */ | |
65eb3dc6 | 60 | /** |
ee2f154a | 61 | * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure |
65eb3dc6 KD |
62 | * @work: identifier for the completion structure |
63 | * | |
64 | * This macro declares and initializes a completion structure on the kernel | |
65 | * stack. | |
66 | */ | |
8b3db9c5 IM |
67 | #ifdef CONFIG_LOCKDEP |
68 | # define DECLARE_COMPLETION_ONSTACK(work) \ | |
f86bf9b7 | 69 | struct completion work = COMPLETION_INITIALIZER_ONSTACK(work) |
a7967bc3 BP |
70 | # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) \ |
71 | struct completion work = COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) | |
8b3db9c5 IM |
72 | #else |
73 | # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work) | |
a7967bc3 | 74 | # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) DECLARE_COMPLETION(work) |
8b3db9c5 IM |
75 | #endif |
76 | ||
65eb3dc6 | 77 | /** |
ee2f154a | 78 | * init_completion - Initialize a dynamically allocated completion |
c32f74ab | 79 | * @x: pointer to completion structure that is to be initialized |
65eb3dc6 KD |
80 | * |
81 | * This inline function will initialize a dynamically created completion | |
82 | * structure. | |
83 | */ | |
b6498aad | 84 | static inline void init_completion(struct completion *x) |
1da177e4 LT |
85 | { |
86 | x->done = 0; | |
a5c6234e | 87 | init_swait_queue_head(&x->wait); |
1da177e4 LT |
88 | } |
89 | ||
c32f74ab WS |
90 | /** |
91 | * reinit_completion - reinitialize a completion structure | |
92 | * @x: pointer to completion structure that is to be reinitialized | |
93 | * | |
94 | * This inline function should be used to reinitialize a completion structure so it can | |
95 | * be reused. This is especially important after complete_all() is used. | |
96 | */ | |
97 | static inline void reinit_completion(struct completion *x) | |
98 | { | |
99 | x->done = 0; | |
100 | } | |
101 | ||
b15136e9 | 102 | extern void wait_for_completion(struct completion *); |
686855f5 | 103 | extern void wait_for_completion_io(struct completion *); |
b15136e9 | 104 | extern int wait_for_completion_interruptible(struct completion *x); |
009e577e | 105 | extern int wait_for_completion_killable(struct completion *x); |
b15136e9 IM |
106 | extern unsigned long wait_for_completion_timeout(struct completion *x, |
107 | unsigned long timeout); | |
686855f5 VD |
108 | extern unsigned long wait_for_completion_io_timeout(struct completion *x, |
109 | unsigned long timeout); | |
6bf41237 N |
110 | extern long wait_for_completion_interruptible_timeout( |
111 | struct completion *x, unsigned long timeout); | |
112 | extern long wait_for_completion_killable_timeout( | |
113 | struct completion *x, unsigned long timeout); | |
be4de352 DC |
114 | extern bool try_wait_for_completion(struct completion *x); |
115 | extern bool completion_done(struct completion *x); | |
b15136e9 IM |
116 | |
117 | extern void complete(struct completion *); | |
118 | extern void complete_all(struct completion *); | |
1da177e4 | 119 | |
1da177e4 | 120 | #endif |