]>
git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/blob - include/linux/completion.h
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>
15 * struct completion - structure used to maintain state for a "completion"
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.
21 * See also: complete(), wait_for_completion() (and friends _timeout,
22 * _interruptible, _interruptible_timeout, and _killable), init_completion(),
23 * reinit_completion(), and macros DECLARE_COMPLETION(),
24 * DECLARE_COMPLETION_ONSTACK().
28 wait_queue_head_t wait
;
31 #define init_completion_map(x, m) __init_completion(x)
32 #define init_completion(x) __init_completion(x)
33 static inline void complete_acquire(struct completion
*x
) {}
34 static inline void complete_release(struct completion
*x
) {}
35 static inline void complete_release_commit(struct completion
*x
) {}
37 #define COMPLETION_INITIALIZER(work) \
38 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
40 #define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \
41 (*({ init_completion_map(&(work), &(map)); &(work); }))
43 #define COMPLETION_INITIALIZER_ONSTACK(work) \
44 (*({ init_completion(&work); &work; }))
47 * DECLARE_COMPLETION - declare and initialize a completion structure
48 * @work: identifier for the completion structure
50 * This macro declares and initializes a completion structure. Generally used
51 * for static declarations. You should use the _ONSTACK variant for automatic
54 #define DECLARE_COMPLETION(work) \
55 struct completion work = COMPLETION_INITIALIZER(work)
58 * Lockdep needs to run a non-constant initializer for on-stack
59 * completions - so we use the _ONSTACK() variant for those that
60 * are on the kernel stack:
63 * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure
64 * @work: identifier for the completion structure
66 * This macro declares and initializes a completion structure on the kernel
70 # define DECLARE_COMPLETION_ONSTACK(work) \
71 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
72 # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) \
73 struct completion work = COMPLETION_INITIALIZER_ONSTACK_MAP(work, map)
75 # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
76 # define DECLARE_COMPLETION_ONSTACK_MAP(work, map) DECLARE_COMPLETION(work)
80 * init_completion - Initialize a dynamically allocated completion
81 * @x: pointer to completion structure that is to be initialized
83 * This inline function will initialize a dynamically created completion
86 static inline void __init_completion(struct completion
*x
)
89 init_waitqueue_head(&x
->wait
);
93 * reinit_completion - reinitialize a completion structure
94 * @x: pointer to completion structure that is to be reinitialized
96 * This inline function should be used to reinitialize a completion structure so it can
97 * be reused. This is especially important after complete_all() is used.
99 static inline void reinit_completion(struct completion
*x
)
104 extern void wait_for_completion(struct completion
*);
105 extern void wait_for_completion_io(struct completion
*);
106 extern int wait_for_completion_interruptible(struct completion
*x
);
107 extern int wait_for_completion_killable(struct completion
*x
);
108 extern unsigned long wait_for_completion_timeout(struct completion
*x
,
109 unsigned long timeout
);
110 extern unsigned long wait_for_completion_io_timeout(struct completion
*x
,
111 unsigned long timeout
);
112 extern long wait_for_completion_interruptible_timeout(
113 struct completion
*x
, unsigned long timeout
);
114 extern long wait_for_completion_killable_timeout(
115 struct completion
*x
, unsigned long timeout
);
116 extern bool try_wait_for_completion(struct completion
*x
);
117 extern bool completion_done(struct completion
*x
);
119 extern void complete(struct completion
*);
120 extern void complete_all(struct completion
*);