1
2#ifndef __LINUX_COMPLETION_H
3#define __LINUX_COMPLETION_H
4
5
6
7
8
9
10
11
12#include <linux/wait.h>
13#ifdef CONFIG_LOCKDEP_COMPLETIONS
14#include <linux/lockdep.h>
15#endif
16
17
18
19
20
21
22
23
24
25
26
27
28
29struct completion {
30 unsigned int done;
31 wait_queue_head_t wait;
32#ifdef CONFIG_LOCKDEP_COMPLETIONS
33 struct lockdep_map_cross map;
34#endif
35};
36
37#ifdef CONFIG_LOCKDEP_COMPLETIONS
38static inline void complete_acquire(struct completion *x)
39{
40 lock_acquire_exclusive((struct lockdep_map *)&x->map, 0, 0, NULL, _RET_IP_);
41}
42
43static inline void complete_release(struct completion *x)
44{
45 lock_release((struct lockdep_map *)&x->map, 0, _RET_IP_);
46}
47
48static inline void complete_release_commit(struct completion *x)
49{
50 lock_commit_crosslock((struct lockdep_map *)&x->map);
51}
52
53#define init_completion(x) \
54do { \
55 static struct lock_class_key __key; \
56 lockdep_init_map_crosslock((struct lockdep_map *)&(x)->map, \
57 "(complete)" #x, \
58 &__key, 0); \
59 __init_completion(x); \
60} while (0)
61#else
62#define init_completion(x) __init_completion(x)
63static inline void complete_acquire(struct completion *x) {}
64static inline void complete_release(struct completion *x) {}
65static inline void complete_release_commit(struct completion *x) {}
66#endif
67
68#ifdef CONFIG_LOCKDEP_COMPLETIONS
69#define COMPLETION_INITIALIZER(work) \
70 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait), \
71 STATIC_CROSS_LOCKDEP_MAP_INIT("(complete)" #work, &(work)) }
72#else
73#define COMPLETION_INITIALIZER(work) \
74 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
75#endif
76
77#define COMPLETION_INITIALIZER_ONSTACK(work) \
78 (*({ init_completion(&work); &work; }))
79
80
81
82
83
84
85
86
87
88#define DECLARE_COMPLETION(work) \
89 struct completion work = COMPLETION_INITIALIZER(work)
90
91
92
93
94
95
96
97
98
99
100
101
102
103#ifdef CONFIG_LOCKDEP
104# define DECLARE_COMPLETION_ONSTACK(work) \
105 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
106#else
107# define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
108#endif
109
110
111
112
113
114
115
116
117static inline void __init_completion(struct completion *x)
118{
119 x->done = 0;
120 init_waitqueue_head(&x->wait);
121}
122
123
124
125
126
127
128
129
130static inline void reinit_completion(struct completion *x)
131{
132 x->done = 0;
133}
134
135extern void wait_for_completion(struct completion *);
136extern void wait_for_completion_io(struct completion *);
137extern int wait_for_completion_interruptible(struct completion *x);
138extern int wait_for_completion_killable(struct completion *x);
139extern unsigned long wait_for_completion_timeout(struct completion *x,
140 unsigned long timeout);
141extern unsigned long wait_for_completion_io_timeout(struct completion *x,
142 unsigned long timeout);
143extern long wait_for_completion_interruptible_timeout(
144 struct completion *x, unsigned long timeout);
145extern long wait_for_completion_killable_timeout(
146 struct completion *x, unsigned long timeout);
147extern bool try_wait_for_completion(struct completion *x);
148extern bool completion_done(struct completion *x);
149
150extern void complete(struct completion *);
151extern void complete_all(struct completion *);
152
153#endif
154