]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/completion.h
docbook: add more wait/wake/completion to device-drivers docbook
[net-next-2.6.git] / include / linux / completion.h
CommitLineData
1da177e4
LT
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.c for details.
9 */
10
11#include <linux/wait.h>
12
ee2f154a 13/*
65eb3dc6
KD
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 * and macros DECLARE_COMPLETION(), DECLARE_COMPLETION_ONSTACK(), and
23 * INIT_COMPLETION().
24 */
1da177e4
LT
25struct 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
f86bf9b7
IM
33#define COMPLETION_INITIALIZER_ONSTACK(work) \
34 ({ init_completion(&work); work; })
35
65eb3dc6 36/**
ee2f154a 37 * DECLARE_COMPLETION - declare and initialize a completion structure
65eb3dc6
KD
38 * @work: identifier for the completion structure
39 *
40 * This macro declares and initializes a completion structure. Generally used
41 * for static declarations. You should use the _ONSTACK variant for automatic
42 * variables.
43 */
1da177e4
LT
44#define DECLARE_COMPLETION(work) \
45 struct completion work = COMPLETION_INITIALIZER(work)
46
8b3db9c5
IM
47/*
48 * Lockdep needs to run a non-constant initializer for on-stack
49 * completions - so we use the _ONSTACK() variant for those that
50 * are on the kernel stack:
51 */
65eb3dc6 52/**
ee2f154a 53 * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure
65eb3dc6
KD
54 * @work: identifier for the completion structure
55 *
56 * This macro declares and initializes a completion structure on the kernel
57 * stack.
58 */
8b3db9c5
IM
59#ifdef CONFIG_LOCKDEP
60# define DECLARE_COMPLETION_ONSTACK(work) \
f86bf9b7 61 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
8b3db9c5
IM
62#else
63# define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
64#endif
65
65eb3dc6 66/**
ee2f154a 67 * init_completion - Initialize a dynamically allocated completion
65eb3dc6
KD
68 * @x: completion structure that is to be initialized
69 *
70 * This inline function will initialize a dynamically created completion
71 * structure.
72 */
1da177e4
LT
73static inline void init_completion(struct completion *x)
74{
75 x->done = 0;
76 init_waitqueue_head(&x->wait);
77}
78
b15136e9
IM
79extern void wait_for_completion(struct completion *);
80extern int wait_for_completion_interruptible(struct completion *x);
009e577e 81extern int wait_for_completion_killable(struct completion *x);
b15136e9
IM
82extern unsigned long wait_for_completion_timeout(struct completion *x,
83 unsigned long timeout);
84extern unsigned long wait_for_completion_interruptible_timeout(
85 struct completion *x, unsigned long timeout);
0aa12fb4
SW
86extern unsigned long wait_for_completion_killable_timeout(
87 struct completion *x, unsigned long timeout);
be4de352
DC
88extern bool try_wait_for_completion(struct completion *x);
89extern bool completion_done(struct completion *x);
b15136e9
IM
90
91extern void complete(struct completion *);
92extern void complete_all(struct completion *);
1da177e4 93
65eb3dc6 94/**
ee2f154a 95 * INIT_COMPLETION - reinitialize a completion structure
65eb3dc6
KD
96 * @x: completion structure to be reinitialized
97 *
98 * This macro should be used to reinitialize a completion structure so it can
99 * be reused. This is especially important after complete_all() is used.
100 */
1da177e4
LT
101#define INIT_COMPLETION(x) ((x).done = 0)
102
39d2f1ab 103
1da177e4 104#endif