Linux Audio

Check our new training course

Loading...
v5.9
  1/* SPDX-License-Identifier: GPL-2.0 */
  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.
  9 * See kernel/sched/completion.c for details.
 10 */
 11
 12#include <linux/swait.h>
 13
 14/*
 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(),
 23 * reinit_completion(), and macros DECLARE_COMPLETION(),
 24 * DECLARE_COMPLETION_ONSTACK().
 25 */
 26struct completion {
 27	unsigned int done;
 28	struct swait_queue_head wait;
 29};
 30
 31#define init_completion_map(x, m) __init_completion(x)
 32#define init_completion(x) __init_completion(x)
 33static inline void complete_acquire(struct completion *x) {}
 34static inline void complete_release(struct completion *x) {}
 35
 36#define COMPLETION_INITIALIZER(work) \
 37	{ 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
 38
 39#define COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) \
 40	(*({ init_completion_map(&(work), &(map)); &(work); }))
 41
 42#define COMPLETION_INITIALIZER_ONSTACK(work) \
 43	(*({ init_completion(&work); &work; }))
 44
 45/**
 46 * DECLARE_COMPLETION - declare and initialize a completion structure
 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 */
 53#define DECLARE_COMPLETION(work) \
 54	struct completion work = COMPLETION_INITIALIZER(work)
 55
 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 */
 61/**
 62 * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure
 63 * @work:  identifier for the completion structure
 64 *
 65 * This macro declares and initializes a completion structure on the kernel
 66 * stack.
 67 */
 68#ifdef CONFIG_LOCKDEP
 69# define DECLARE_COMPLETION_ONSTACK(work) \
 70	struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
 71# define DECLARE_COMPLETION_ONSTACK_MAP(work, map) \
 72	struct completion work = COMPLETION_INITIALIZER_ONSTACK_MAP(work, map)
 73#else
 74# define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
 75# define DECLARE_COMPLETION_ONSTACK_MAP(work, map) DECLARE_COMPLETION(work)
 76#endif
 77
 78/**
 79 * init_completion - Initialize a dynamically allocated completion
 80 * @x:  pointer to completion structure that is to be initialized
 81 *
 82 * This inline function will initialize a dynamically created completion
 83 * structure.
 84 */
 85static inline void __init_completion(struct completion *x)
 86{
 87	x->done = 0;
 88	init_swait_queue_head(&x->wait);
 89}
 90
 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
103extern void wait_for_completion(struct completion *);
104extern void wait_for_completion_io(struct completion *);
105extern int wait_for_completion_interruptible(struct completion *x);
106extern int wait_for_completion_killable(struct completion *x);
107extern unsigned long wait_for_completion_timeout(struct completion *x,
108						   unsigned long timeout);
109extern unsigned long wait_for_completion_io_timeout(struct completion *x,
110						    unsigned long timeout);
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);
115extern bool try_wait_for_completion(struct completion *x);
116extern bool completion_done(struct completion *x);
117
118extern void complete(struct completion *);
119extern void complete_all(struct completion *);
120
121#endif
v4.10.11
 
  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/completion.c for details.
  9 */
 10
 11#include <linux/wait.h>
 12
 13/*
 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 * reinit_completion(), and macros DECLARE_COMPLETION(),
 23 * DECLARE_COMPLETION_ONSTACK().
 24 */
 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
 33#define COMPLETION_INITIALIZER_ONSTACK(work) \
 34	({ init_completion(&work); work; })
 35
 36/**
 37 * DECLARE_COMPLETION - declare and initialize a completion structure
 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 */
 44#define DECLARE_COMPLETION(work) \
 45	struct completion work = COMPLETION_INITIALIZER(work)
 46
 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 */
 52/**
 53 * DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure
 54 * @work:  identifier for the completion structure
 55 *
 56 * This macro declares and initializes a completion structure on the kernel
 57 * stack.
 58 */
 59#ifdef CONFIG_LOCKDEP
 60# define DECLARE_COMPLETION_ONSTACK(work) \
 61	struct completion work = COMPLETION_INITIALIZER_ONSTACK(work)
 
 
 62#else
 63# define DECLARE_COMPLETION_ONSTACK(work) DECLARE_COMPLETION(work)
 
 64#endif
 65
 66/**
 67 * init_completion - Initialize a dynamically allocated completion
 68 * @x:  pointer to completion structure that is to be initialized
 69 *
 70 * This inline function will initialize a dynamically created completion
 71 * structure.
 72 */
 73static inline void init_completion(struct completion *x)
 74{
 75	x->done = 0;
 76	init_waitqueue_head(&x->wait);
 77}
 78
 79/**
 80 * reinit_completion - reinitialize a completion structure
 81 * @x:  pointer to completion structure that is to be reinitialized
 82 *
 83 * This inline function should be used to reinitialize a completion structure so it can
 84 * be reused. This is especially important after complete_all() is used.
 85 */
 86static inline void reinit_completion(struct completion *x)
 87{
 88	x->done = 0;
 89}
 90
 91extern void wait_for_completion(struct completion *);
 92extern void wait_for_completion_io(struct completion *);
 93extern int wait_for_completion_interruptible(struct completion *x);
 94extern int wait_for_completion_killable(struct completion *x);
 95extern unsigned long wait_for_completion_timeout(struct completion *x,
 96						   unsigned long timeout);
 97extern unsigned long wait_for_completion_io_timeout(struct completion *x,
 98						    unsigned long timeout);
 99extern long wait_for_completion_interruptible_timeout(
100	struct completion *x, unsigned long timeout);
101extern long wait_for_completion_killable_timeout(
102	struct completion *x, unsigned long timeout);
103extern bool try_wait_for_completion(struct completion *x);
104extern bool completion_done(struct completion *x);
105
106extern void complete(struct completion *);
107extern void complete_all(struct completion *);
108
109#endif