xref: /freebsd/sys/compat/linuxkpi/common/include/linux/completion.h (revision 307f78f3ed90a4145eeb2c8cc79bc95b2666f57a)
18d59ecb2SHans Petter Selasky /*-
28d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Isilon Systems, Inc.
38d59ecb2SHans Petter Selasky  * Copyright (c) 2010 iX Systems, Inc.
48d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Panasas, Inc.
58d59ecb2SHans Petter Selasky  * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
68d59ecb2SHans Petter Selasky  * All rights reserved.
78d59ecb2SHans Petter Selasky  *
88d59ecb2SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
98d59ecb2SHans Petter Selasky  * modification, are permitted provided that the following conditions
108d59ecb2SHans Petter Selasky  * are met:
118d59ecb2SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
128d59ecb2SHans Petter Selasky  *    notice unmodified, this list of conditions, and the following
138d59ecb2SHans Petter Selasky  *    disclaimer.
148d59ecb2SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
158d59ecb2SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
168d59ecb2SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
178d59ecb2SHans Petter Selasky  *
188d59ecb2SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198d59ecb2SHans Petter Selasky  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208d59ecb2SHans Petter Selasky  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218d59ecb2SHans Petter Selasky  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228d59ecb2SHans Petter Selasky  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238d59ecb2SHans Petter Selasky  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248d59ecb2SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258d59ecb2SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268d59ecb2SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278d59ecb2SHans Petter Selasky  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288d59ecb2SHans Petter Selasky  *
298d59ecb2SHans Petter Selasky  * $FreeBSD$
308d59ecb2SHans Petter Selasky  */
31*307f78f3SVladimir Kondratyev #ifndef	_LINUXKPI_LINUX_COMPLETION_H_
32*307f78f3SVladimir Kondratyev #define	_LINUXKPI_LINUX_COMPLETION_H_
338d59ecb2SHans Petter Selasky 
348d59ecb2SHans Petter Selasky #include <linux/errno.h>
358d59ecb2SHans Petter Selasky 
368d59ecb2SHans Petter Selasky struct completion {
378d59ecb2SHans Petter Selasky 	unsigned int done;
388d59ecb2SHans Petter Selasky };
398d59ecb2SHans Petter Selasky 
408d59ecb2SHans Petter Selasky #define	INIT_COMPLETION(c) \
418d59ecb2SHans Petter Selasky 	((c).done = 0)
428d59ecb2SHans Petter Selasky #define	init_completion(c) \
43fe68f570SHans Petter Selasky 	do { (c)->done = 0; } while (0)
44fe68f570SHans Petter Selasky #define	reinit_completion(c) \
45fe68f570SHans Petter Selasky 	do { (c)->done = 0; } while (0)
468d59ecb2SHans Petter Selasky #define	complete(c)				\
478d59ecb2SHans Petter Selasky 	linux_complete_common((c), 0)
488d59ecb2SHans Petter Selasky #define	complete_all(c)				\
498d59ecb2SHans Petter Selasky 	linux_complete_common((c), 1)
508d59ecb2SHans Petter Selasky #define	wait_for_completion(c)			\
518d59ecb2SHans Petter Selasky 	linux_wait_for_common((c), 0)
52f6d45524SHans Petter Selasky #define	wait_for_completion_interruptible(c)	\
538d59ecb2SHans Petter Selasky 	linux_wait_for_common((c), 1)
548d59ecb2SHans Petter Selasky #define	wait_for_completion_timeout(c, timeout)	\
558d59ecb2SHans Petter Selasky 	linux_wait_for_timeout_common((c), (timeout), 0)
568d59ecb2SHans Petter Selasky #define	wait_for_completion_interruptible_timeout(c, timeout)	\
578d59ecb2SHans Petter Selasky 	linux_wait_for_timeout_common((c), (timeout), 1)
588d59ecb2SHans Petter Selasky #define	try_wait_for_completion(c) \
598d59ecb2SHans Petter Selasky 	linux_try_wait_for_completion(c)
608d59ecb2SHans Petter Selasky #define	completion_done(c) \
618d59ecb2SHans Petter Selasky 	linux_completion_done(c)
628d59ecb2SHans Petter Selasky 
638d59ecb2SHans Petter Selasky extern void linux_complete_common(struct completion *, int);
64f6800be3SHans Petter Selasky extern int linux_wait_for_common(struct completion *, int);
65f6800be3SHans Petter Selasky extern int linux_wait_for_timeout_common(struct completion *, int, int);
668d59ecb2SHans Petter Selasky extern int linux_try_wait_for_completion(struct completion *);
678d59ecb2SHans Petter Selasky extern int linux_completion_done(struct completion *);
688d59ecb2SHans Petter Selasky 
69*307f78f3SVladimir Kondratyev #endif					/* _LINUXKPI_LINUX_COMPLETION_H_ */
70