]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/completion.h
bcache in userspace; userspace fsck
[bcachefs-tools-debian] / include / linux / completion.h
1 #ifndef __LINUX_COMPLETION_H
2 #define __LINUX_COMPLETION_H
3
4 /*
5  * (C) Copyright 2001 Linus Torvalds
6  *
7  * Atomic wait-for-completion handler data structures.
8  * See kernel/sched/completion.c for details.
9  */
10
11 #include <linux/wait.h>
12
13 /*
14  * struct completion - structure used to maintain state for a "completion"
15  *
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.
19  *
20  * See also:  complete(), wait_for_completion() (and friends _timeout,
21  * _interruptible, _interruptible_timeout, and _killable), init_completion(),
22  * reinit_completion(), and macros DECLARE_COMPLETION(),
23  * DECLARE_COMPLETION_ONSTACK().
24  */
25 struct completion {
26         unsigned int done;
27         wait_queue_head_t wait;
28 };
29
30 #define COMPLETION_INITIALIZER(work) \
31         { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
32
33 #define COMPLETION_INITIALIZER_ONSTACK(work) \
34         ({ init_completion(&work); work; })
35
36 #define DECLARE_COMPLETION(work) \
37         struct completion work = COMPLETION_INITIALIZER(work)
38 #define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
39
40 /**
41  * init_completion - Initialize a dynamically allocated completion
42  * @x:  pointer to completion structure that is to be initialized
43  *
44  * This inline function will initialize a dynamically created completion
45  * structure.
46  */
47 static inline void init_completion(struct completion *x)
48 {
49         x->done = 0;
50         init_waitqueue_head(&x->wait);
51 }
52
53 /**
54  * reinit_completion - reinitialize a completion structure
55  * @x:  pointer to completion structure that is to be reinitialized
56  *
57  * This inline function should be used to reinitialize a completion structure so it can
58  * be reused. This is especially important after complete_all() is used.
59  */
60 static inline void reinit_completion(struct completion *x)
61 {
62         x->done = 0;
63 }
64
65 extern void wait_for_completion(struct completion *);
66 extern void wait_for_completion_io(struct completion *);
67 extern int wait_for_completion_interruptible(struct completion *x);
68 extern int wait_for_completion_killable(struct completion *x);
69 extern unsigned long wait_for_completion_timeout(struct completion *x,
70                                                    unsigned long timeout);
71 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72                                                     unsigned long timeout);
73 extern long wait_for_completion_interruptible_timeout(
74         struct completion *x, unsigned long timeout);
75 extern long wait_for_completion_killable_timeout(
76         struct completion *x, unsigned long timeout);
77 extern bool try_wait_for_completion(struct completion *x);
78 extern bool completion_done(struct completion *x);
79
80 extern void complete(struct completion *);
81 extern void complete_all(struct completion *);
82
83 #endif