1 #ifndef __LINUX_COMPLETION_H
2 #define __LINUX_COMPLETION_H
5 * (C) Copyright 2001 Linus Torvalds
7 * Atomic wait-for-completion handler data structures.
8 * See kernel/sched.c for details.
11 #include <linux/wait.h>
15 wait_queue_head_t wait
;
18 #define COMPLETION_INITIALIZER(work) \
19 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
21 #define COMPLETION_INITIALIZER_ONSTACK(work) \
22 ({ init_completion(&work); work; })
24 #define DECLARE_COMPLETION(work) \
25 struct completion work = COMPLETION_INITIALIZER(work)
28 * Lockdep needs to run a non-constant initializer for on-stack
29 * completions - so we use the _ONSTACK() variant for those that
30 * are on the kernel stack:
33 # define DECLARE_COMPLETION_ONSTACK(work) \
34 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
36 # define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
39 static inline void init_completion(struct completion
*x
)
42 init_waitqueue_head(&x
->wait
);
45 extern void wait_for_completion(struct completion
*);
46 extern int wait_for_completion_interruptible(struct completion
*x
);
47 extern int wait_for_completion_killable(struct completion
*x
);
48 extern unsigned long wait_for_completion_timeout(struct completion
*x
,
49 unsigned long timeout
);
50 extern unsigned long wait_for_completion_interruptible_timeout(
51 struct completion
*x
, unsigned long timeout
);
52 extern bool try_wait_for_completion(struct completion
*x
);
53 extern bool completion_done(struct completion
*x
);
55 extern void complete(struct completion
*);
56 extern void complete_all(struct completion
*);
58 #define INIT_COMPLETION(x) ((x).done = 0)