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/completion.c for details.
11 #include <linux/wait.h>
14 * struct completion - structure used to maintain state for a "completion"
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.
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().
27 wait_queue_head_t wait;
30 #define COMPLETION_INITIALIZER(work) \
31 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
33 #define COMPLETION_INITIALIZER_ONSTACK(work) \
34 ({ init_completion(&work); work; })
36 #define DECLARE_COMPLETION(work) \
37 struct completion work = COMPLETION_INITIALIZER(work)
38 #define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
41 * init_completion - Initialize a dynamically allocated completion
42 * @x: pointer to completion structure that is to be initialized
44 * This inline function will initialize a dynamically created completion
47 static inline void init_completion(struct completion *x)
50 init_waitqueue_head(&x->wait);
54 * reinit_completion - reinitialize a completion structure
55 * @x: pointer to completion structure that is to be reinitialized
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.
60 static inline void reinit_completion(struct completion *x)
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);
80 extern void complete(struct completion *);
81 extern void complete_all(struct completion *);