]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/completion.h
net: rtnetlink: validate IFLA_MTU attribute in rtnl_create_link()
[mirror_ubuntu-bionic-kernel.git] / include / linux / completion.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2#ifndef __LINUX_COMPLETION_H
3#define __LINUX_COMPLETION_H
4
5/*
6 * (C) Copyright 2001 Linus Torvalds
7 *
8 * Atomic wait-for-completion handler data structures.
b8a21626 9 * See kernel/sched/completion.c for details.
1da177e4
LT
10 */
11
12#include <linux/wait.h>
13
ee2f154a 14/*
65eb3dc6
KD
15 * struct completion - structure used to maintain state for a "completion"
16 *
17 * This is the opaque structure used to maintain the state for a "completion".
18 * Completions currently use a FIFO to queue threads that have to wait for
19 * the "completion" event.
20 *
21 * See also: complete(), wait_for_completion() (and friends _timeout,
22 * _interruptible, _interruptible_timeout, and _killable), init_completion(),
c32f74ab
WS
23 * reinit_completion(), and macros DECLARE_COMPLETION(),
24 * DECLARE_COMPLETION_ONSTACK().
65eb3dc6 25 */
1da177e4
LT
26struct completion {
27 unsigned int done;
28 wait_queue_head_t wait;
29};
30
a7967bc3 31#define init_completion_map(x, m) __init_completion(x)
cd8084f9
BP
32#define init_completion(x) __init_completion(x)
33static inline void complete_acquire(struct completion *x) {}
34static inline void complete_release(struct completion *x) {}
cd8084f9 35
1da177e4
LT
36#define COMPLETION_INITIALIZER(work) \
37 { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
38
a7967bc3
BP
39#define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \
40 (*({ init_completion_map(&(work), &(map)); &(work); }))
41
f86bf9b7 42#define COMPLETION_INITIALIZER_ONSTACK(work) \
ec81048c 43 (*({ init_completion(&work); &work; }))
f86bf9b7 44
65eb3dc6 45/**
ee2f154a 46 * DECLARE_COMPLETION - declare and initialize a completion structure
65eb3dc6
KD
47 * @work: identifier for the completion structure
48 *
49 * This macro declares and initializes a completion structure. Generally used
50 * for static declarations. You should use the _ONSTACK variant for automatic
51 * variables.
52 */
1da177e4
LT
53#define DECLARE_COMPLETION(work) \
54 struct completion work = COMPLETION_INITIALIZER(work)
55
8b3db9c5
IM
56/*
57 * Lockdep needs to run a non-constant initializer for on-stack
58 * completions - so we use the _ONSTACK() variant for those that
59 * are on the kernel stack:
60 */
65eb3dc6 61/**
ee2f154a 62 * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure
65eb3dc6
KD
63 * @work: identifier for the completion structure
64 *
65 * This macro declares and initializes a completion structure on the kernel
66 * stack.
67 */
8b3db9c5
IM
68#ifdef CONFIG_LOCKDEP
69# define DECLARE_COMPLETION_ONSTACK(work) \
f86bf9b7 70 struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
a7967bc3
BP
71# define DECLARE_COMPLETION_ONSTACK_MAP(work, map) \
72 struct completion work = COMPLETION_INITIALIZER_ONSTACK_MAP(work, map)
8b3db9c5
IM
73#else
74# define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
a7967bc3 75# define DECLARE_COMPLETION_ONSTACK_MAP(work, map) DECLARE_COMPLETION(work)
8b3db9c5
IM
76#endif
77
65eb3dc6 78/**
ee2f154a 79 * init_completion - Initialize a dynamically allocated completion
c32f74ab 80 * @x: pointer to completion structure that is to be initialized
65eb3dc6
KD
81 *
82 * This inline function will initialize a dynamically created completion
83 * structure.
84 */
cd8084f9 85static inline void __init_completion(struct completion *x)
1da177e4
LT
86{
87 x->done = 0;
88 init_waitqueue_head(&x->wait);
89}
90
c32f74ab
WS
91/**
92 * reinit_completion - reinitialize a completion structure
93 * @x: pointer to completion structure that is to be reinitialized
94 *
95 * This inline function should be used to reinitialize a completion structure so it can
96 * be reused. This is especially important after complete_all() is used.
97 */
98static inline void reinit_completion(struct completion *x)
99{
100 x->done = 0;
101}
102
b15136e9 103extern void wait_for_completion(struct completion *);
686855f5 104extern void wait_for_completion_io(struct completion *);
b15136e9 105extern int wait_for_completion_interruptible(struct completion *x);
009e577e 106extern int wait_for_completion_killable(struct completion *x);
b15136e9
IM
107extern unsigned long wait_for_completion_timeout(struct completion *x,
108 unsigned long timeout);
686855f5
VD
109extern unsigned long wait_for_completion_io_timeout(struct completion *x,
110 unsigned long timeout);
6bf41237
N
111extern long wait_for_completion_interruptible_timeout(
112 struct completion *x, unsigned long timeout);
113extern long wait_for_completion_killable_timeout(
114 struct completion *x, unsigned long timeout);
be4de352
DC
115extern bool try_wait_for_completion(struct completion *x);
116extern bool completion_done(struct completion *x);
b15136e9
IM
117
118extern void complete(struct completion *);
119extern void complete_all(struct completion *);
1da177e4 120
1da177e4 121#endif