xref: /src/sys/compat/linuxkpi/common/include/linux/completion.h (revision 325aa4dbd10d04a61a9529e1d76212b5649b3c73)
1aa0a1e58SJeff Roberson /*-
2aa0a1e58SJeff Roberson  * Copyright (c) 2010 Isilon Systems, Inc.
3aa0a1e58SJeff Roberson  * Copyright (c) 2010 iX Systems, Inc.
4aa0a1e58SJeff Roberson  * Copyright (c) 2010 Panasas, Inc.
5c7818b48SHans Petter Selasky  * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
6aa0a1e58SJeff Roberson  * All rights reserved.
7aa0a1e58SJeff Roberson  *
8aa0a1e58SJeff Roberson  * Redistribution and use in source and binary forms, with or without
9aa0a1e58SJeff Roberson  * modification, are permitted provided that the following conditions
10aa0a1e58SJeff Roberson  * are met:
11aa0a1e58SJeff Roberson  * 1. Redistributions of source code must retain the above copyright
12aa0a1e58SJeff Roberson  *    notice unmodified, this list of conditions, and the following
13aa0a1e58SJeff Roberson  *    disclaimer.
14aa0a1e58SJeff Roberson  * 2. Redistributions in binary form must reproduce the above copyright
15aa0a1e58SJeff Roberson  *    notice, this list of conditions and the following disclaimer in the
16aa0a1e58SJeff Roberson  *    documentation and/or other materials provided with the distribution.
17aa0a1e58SJeff Roberson  *
18aa0a1e58SJeff Roberson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19aa0a1e58SJeff Roberson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20aa0a1e58SJeff Roberson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21aa0a1e58SJeff Roberson  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22aa0a1e58SJeff Roberson  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23aa0a1e58SJeff Roberson  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24aa0a1e58SJeff Roberson  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25aa0a1e58SJeff Roberson  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26aa0a1e58SJeff Roberson  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27aa0a1e58SJeff Roberson  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28aa0a1e58SJeff Roberson  */
29307f78f3SVladimir Kondratyev #ifndef	_LINUXKPI_LINUX_COMPLETION_H_
30307f78f3SVladimir Kondratyev #define	_LINUXKPI_LINUX_COMPLETION_H_
31aa0a1e58SJeff Roberson 
32aa0a1e58SJeff Roberson #include <linux/errno.h>
33aa0a1e58SJeff Roberson 
34aa0a1e58SJeff Roberson struct completion {
35aa0a1e58SJeff Roberson 	unsigned int done;
36aa0a1e58SJeff Roberson };
37aa0a1e58SJeff Roberson 
38932493ffSHans Petter Selasky #define	INIT_COMPLETION(c) \
39932493ffSHans Petter Selasky 	((c).done = 0)
40932493ffSHans Petter Selasky #define	init_completion(c) \
41fe68f570SHans Petter Selasky 	do { (c)->done = 0; } while (0)
42fe68f570SHans Petter Selasky #define	reinit_completion(c) \
43fe68f570SHans Petter Selasky 	do { (c)->done = 0; } while (0)
44932493ffSHans Petter Selasky #define	complete(c)				\
45932493ffSHans Petter Selasky 	linux_complete_common((c), 0)
46932493ffSHans Petter Selasky #define	complete_all(c)				\
47932493ffSHans Petter Selasky 	linux_complete_common((c), 1)
48932493ffSHans Petter Selasky #define	wait_for_completion(c)			\
49932493ffSHans Petter Selasky 	linux_wait_for_common((c), 0)
50f6d45524SHans Petter Selasky #define	wait_for_completion_interruptible(c)	\
51932493ffSHans Petter Selasky 	linux_wait_for_common((c), 1)
52aa0a1e58SJeff Roberson #define	wait_for_completion_timeout(c, timeout)	\
53932493ffSHans Petter Selasky 	linux_wait_for_timeout_common((c), (timeout), 0)
54aa0a1e58SJeff Roberson #define	wait_for_completion_interruptible_timeout(c, timeout)	\
55932493ffSHans Petter Selasky 	linux_wait_for_timeout_common((c), (timeout), 1)
56932493ffSHans Petter Selasky #define	try_wait_for_completion(c) \
57932493ffSHans Petter Selasky 	linux_try_wait_for_completion(c)
58932493ffSHans Petter Selasky #define	completion_done(c) \
59932493ffSHans Petter Selasky 	linux_completion_done(c)
60aa0a1e58SJeff Roberson 
61932493ffSHans Petter Selasky extern void linux_complete_common(struct completion *, int);
62f6800be3SHans Petter Selasky extern int linux_wait_for_common(struct completion *, int);
63325aa4dbSMark Johnston extern unsigned long linux_wait_for_timeout_common(struct completion *,
64325aa4dbSMark Johnston     unsigned long, int);
65932493ffSHans Petter Selasky extern int linux_try_wait_for_completion(struct completion *);
66932493ffSHans Petter Selasky extern int linux_completion_done(struct completion *);
67aa0a1e58SJeff Roberson 
68307f78f3SVladimir Kondratyev #endif					/* _LINUXKPI_LINUX_COMPLETION_H_ */
69