xref: /src/sys/compat/linuxkpi/common/include/linux/wait_bit.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
10e123c13SEmmanuel Vadot /*-
20e123c13SEmmanuel Vadot  * Copyright (c) 2020 The FreeBSD Foundation
30e123c13SEmmanuel Vadot  *
40e123c13SEmmanuel Vadot  * This software was developed by Emmanuel Vadot under sponsorship
50e123c13SEmmanuel Vadot  * from the FreeBSD Foundation.
60e123c13SEmmanuel Vadot  *
70e123c13SEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
80e123c13SEmmanuel Vadot  * modification, are permitted provided that the following conditions
90e123c13SEmmanuel Vadot  * are met:
100e123c13SEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
110e123c13SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
120e123c13SEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
130e123c13SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
140e123c13SEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
150e123c13SEmmanuel Vadot  *
160e123c13SEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
170e123c13SEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
180e123c13SEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
190e123c13SEmmanuel Vadot  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
200e123c13SEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
210e123c13SEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
220e123c13SEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
230e123c13SEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
240e123c13SEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
250e123c13SEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
260e123c13SEmmanuel Vadot  * SUCH DAMAGE.
270e123c13SEmmanuel Vadot  */
280e123c13SEmmanuel Vadot 
29307f78f3SVladimir Kondratyev #ifndef __LINUXKPI_LINUX_WAITBIT_H__
30307f78f3SVladimir Kondratyev #define	__LINUXKPI_LINUX_WAITBIT_H__
310e123c13SEmmanuel Vadot 
320e123c13SEmmanuel Vadot #include <linux/wait.h>
330e123c13SEmmanuel Vadot #include <linux/bitops.h>
340e123c13SEmmanuel Vadot 
350e123c13SEmmanuel Vadot extern wait_queue_head_t linux_bit_waitq;
360e123c13SEmmanuel Vadot extern wait_queue_head_t linux_var_waitq;
370e123c13SEmmanuel Vadot 
380e123c13SEmmanuel Vadot #define	wait_var_event_killable(var, cond) \
390e123c13SEmmanuel Vadot 	wait_event_killable(linux_var_waitq, cond)
400e123c13SEmmanuel Vadot 
41057f145aSNeel Chauhan #define	wait_var_event_interruptible(var, cond) \
42057f145aSNeel Chauhan 	wait_event_interruptible(linux_var_waitq, cond)
43057f145aSNeel Chauhan 
440e123c13SEmmanuel Vadot static inline void
clear_and_wake_up_bit(int bit,void * word)450e123c13SEmmanuel Vadot clear_and_wake_up_bit(int bit, void *word)
460e123c13SEmmanuel Vadot {
470e123c13SEmmanuel Vadot 	clear_bit_unlock(bit, word);
480e123c13SEmmanuel Vadot 	wake_up_bit(word, bit);
490e123c13SEmmanuel Vadot }
500e123c13SEmmanuel Vadot 
510e123c13SEmmanuel Vadot static inline wait_queue_head_t *
bit_waitqueue(void * word,int bit)520e123c13SEmmanuel Vadot bit_waitqueue(void *word, int bit)
530e123c13SEmmanuel Vadot {
540e123c13SEmmanuel Vadot 
550e123c13SEmmanuel Vadot 	return (&linux_bit_waitq);
560e123c13SEmmanuel Vadot }
570e123c13SEmmanuel Vadot 
580e123c13SEmmanuel Vadot static inline void
wake_up_var(void * var)590e123c13SEmmanuel Vadot wake_up_var(void *var)
600e123c13SEmmanuel Vadot {
610e123c13SEmmanuel Vadot 
620e123c13SEmmanuel Vadot 	wake_up(&linux_var_waitq);
630e123c13SEmmanuel Vadot }
640e123c13SEmmanuel Vadot 
65cb15ed7dSEmmanuel Vadot static inline wait_queue_head_t *
__var_waitqueue(void * p)66cb15ed7dSEmmanuel Vadot __var_waitqueue(void *p)
67cb15ed7dSEmmanuel Vadot {
68cb15ed7dSEmmanuel Vadot 	return (&linux_var_waitq);
69cb15ed7dSEmmanuel Vadot }
70cb15ed7dSEmmanuel Vadot 
71307f78f3SVladimir Kondratyev #endif	/* __LINUXKPI_LINUX_WAITBIT_H__ */
72