xref: /openbmc/linux/include/linux/wait_bit.h (revision 8238b457)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
25dd43ce2SIngo Molnar #ifndef _LINUX_WAIT_BIT_H
35dd43ce2SIngo Molnar #define _LINUX_WAIT_BIT_H
45dd43ce2SIngo Molnar 
55dd43ce2SIngo Molnar /*
65dd43ce2SIngo Molnar  * Linux wait-bit related types and methods:
75dd43ce2SIngo Molnar  */
85dd43ce2SIngo Molnar #include <linux/wait.h>
95dd43ce2SIngo Molnar 
105dd43ce2SIngo Molnar struct wait_bit_key {
115dd43ce2SIngo Molnar 	void			*flags;
125dd43ce2SIngo Molnar 	int			bit_nr;
135dd43ce2SIngo Molnar 	unsigned long		timeout;
145dd43ce2SIngo Molnar };
155dd43ce2SIngo Molnar 
165dd43ce2SIngo Molnar struct wait_bit_queue_entry {
175dd43ce2SIngo Molnar 	struct wait_bit_key	key;
185dd43ce2SIngo Molnar 	struct wait_queue_entry	wq_entry;
195dd43ce2SIngo Molnar };
205dd43ce2SIngo Molnar 
215dd43ce2SIngo Molnar #define __WAIT_BIT_KEY_INITIALIZER(word, bit)					\
225dd43ce2SIngo Molnar 	{ .flags = word, .bit_nr = bit, }
235dd43ce2SIngo Molnar 
245dd43ce2SIngo Molnar typedef int wait_bit_action_f(struct wait_bit_key *key, int mode);
255e4def20SDavid Howells 
265dd43ce2SIngo Molnar void __wake_up_bit(struct wait_queue_head *wq_head, void *word, int bit);
275dd43ce2SIngo Molnar int __wait_on_bit(struct wait_queue_head *wq_head, struct wait_bit_queue_entry *wbq_entry, wait_bit_action_f *action, unsigned int mode);
285dd43ce2SIngo Molnar int __wait_on_bit_lock(struct wait_queue_head *wq_head, struct wait_bit_queue_entry *wbq_entry, wait_bit_action_f *action, unsigned int mode);
295dd43ce2SIngo Molnar void wake_up_bit(void *word, int bit);
305dd43ce2SIngo Molnar int out_of_line_wait_on_bit(void *word, int, wait_bit_action_f *action, unsigned int mode);
315dd43ce2SIngo Molnar int out_of_line_wait_on_bit_timeout(void *word, int, wait_bit_action_f *action, unsigned int mode, unsigned long timeout);
325dd43ce2SIngo Molnar int out_of_line_wait_on_bit_lock(void *word, int, wait_bit_action_f *action, unsigned int mode);
335dd43ce2SIngo Molnar struct wait_queue_head *bit_waitqueue(void *word, int bit);
345822a454SIngo Molnar extern void __init wait_bit_init(void);
355dd43ce2SIngo Molnar 
365dd43ce2SIngo Molnar int wake_bit_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
375dd43ce2SIngo Molnar 
385dd43ce2SIngo Molnar #define DEFINE_WAIT_BIT(name, word, bit)					\
395dd43ce2SIngo Molnar 	struct wait_bit_queue_entry name = {					\
405dd43ce2SIngo Molnar 		.key = __WAIT_BIT_KEY_INITIALIZER(word, bit),			\
415dd43ce2SIngo Molnar 		.wq_entry = {							\
425dd43ce2SIngo Molnar 			.private	= current,				\
435dd43ce2SIngo Molnar 			.func		= wake_bit_function,			\
442055da97SIngo Molnar 			.entry		=					\
452055da97SIngo Molnar 				LIST_HEAD_INIT((name).wq_entry.entry),		\
465dd43ce2SIngo Molnar 		},								\
475dd43ce2SIngo Molnar 	}
485dd43ce2SIngo Molnar 
495e4def20SDavid Howells extern int bit_wait(struct wait_bit_key *key, int mode);
505e4def20SDavid Howells extern int bit_wait_io(struct wait_bit_key *key, int mode);
515e4def20SDavid Howells extern int bit_wait_timeout(struct wait_bit_key *key, int mode);
525e4def20SDavid Howells extern int bit_wait_io_timeout(struct wait_bit_key *key, int mode);
535dd43ce2SIngo Molnar 
545dd43ce2SIngo Molnar /**
555dd43ce2SIngo Molnar  * wait_on_bit - wait for a bit to be cleared
565dd43ce2SIngo Molnar  * @word: the word being waited on, a kernel virtual address
575dd43ce2SIngo Molnar  * @bit: the bit of the word being waited on
585dd43ce2SIngo Molnar  * @mode: the task state to sleep in
595dd43ce2SIngo Molnar  *
605dd43ce2SIngo Molnar  * There is a standard hashed waitqueue table for generic use. This
615dd43ce2SIngo Molnar  * is the part of the hashtable's accessor API that waits on a bit.
625dd43ce2SIngo Molnar  * For instance, if one were to have waiters on a bitflag, one would
635dd43ce2SIngo Molnar  * call wait_on_bit() in threads waiting for the bit to clear.
645dd43ce2SIngo Molnar  * One uses wait_on_bit() where one is waiting for the bit to clear,
655dd43ce2SIngo Molnar  * but has no intention of setting it.
665dd43ce2SIngo Molnar  * Returned value will be zero if the bit was cleared, or non-zero
675dd43ce2SIngo Molnar  * if the process received a signal and the mode permitted wakeup
685dd43ce2SIngo Molnar  * on that signal.
695dd43ce2SIngo Molnar  */
705dd43ce2SIngo Molnar static inline int
wait_on_bit(unsigned long * word,int bit,unsigned mode)715dd43ce2SIngo Molnar wait_on_bit(unsigned long *word, int bit, unsigned mode)
725dd43ce2SIngo Molnar {
735dd43ce2SIngo Molnar 	might_sleep();
74*8238b457SMikulas Patocka 	if (!test_bit_acquire(bit, word))
755dd43ce2SIngo Molnar 		return 0;
765dd43ce2SIngo Molnar 	return out_of_line_wait_on_bit(word, bit,
775dd43ce2SIngo Molnar 				       bit_wait,
785dd43ce2SIngo Molnar 				       mode);
795dd43ce2SIngo Molnar }
805dd43ce2SIngo Molnar 
815dd43ce2SIngo Molnar /**
825dd43ce2SIngo Molnar  * wait_on_bit_io - wait for a bit to be cleared
835dd43ce2SIngo Molnar  * @word: the word being waited on, a kernel virtual address
845dd43ce2SIngo Molnar  * @bit: the bit of the word being waited on
855dd43ce2SIngo Molnar  * @mode: the task state to sleep in
865dd43ce2SIngo Molnar  *
875dd43ce2SIngo Molnar  * Use the standard hashed waitqueue table to wait for a bit
885dd43ce2SIngo Molnar  * to be cleared.  This is similar to wait_on_bit(), but calls
895dd43ce2SIngo Molnar  * io_schedule() instead of schedule() for the actual waiting.
905dd43ce2SIngo Molnar  *
915dd43ce2SIngo Molnar  * Returned value will be zero if the bit was cleared, or non-zero
925dd43ce2SIngo Molnar  * if the process received a signal and the mode permitted wakeup
935dd43ce2SIngo Molnar  * on that signal.
945dd43ce2SIngo Molnar  */
955dd43ce2SIngo Molnar static inline int
wait_on_bit_io(unsigned long * word,int bit,unsigned mode)965dd43ce2SIngo Molnar wait_on_bit_io(unsigned long *word, int bit, unsigned mode)
975dd43ce2SIngo Molnar {
985dd43ce2SIngo Molnar 	might_sleep();
99*8238b457SMikulas Patocka 	if (!test_bit_acquire(bit, word))
1005dd43ce2SIngo Molnar 		return 0;
1015dd43ce2SIngo Molnar 	return out_of_line_wait_on_bit(word, bit,
1025dd43ce2SIngo Molnar 				       bit_wait_io,
1035dd43ce2SIngo Molnar 				       mode);
1045dd43ce2SIngo Molnar }
1055dd43ce2SIngo Molnar 
1065dd43ce2SIngo Molnar /**
1075dd43ce2SIngo Molnar  * wait_on_bit_timeout - wait for a bit to be cleared or a timeout elapses
1085dd43ce2SIngo Molnar  * @word: the word being waited on, a kernel virtual address
1095dd43ce2SIngo Molnar  * @bit: the bit of the word being waited on
1105dd43ce2SIngo Molnar  * @mode: the task state to sleep in
1115dd43ce2SIngo Molnar  * @timeout: timeout, in jiffies
1125dd43ce2SIngo Molnar  *
1135dd43ce2SIngo Molnar  * Use the standard hashed waitqueue table to wait for a bit
1145dd43ce2SIngo Molnar  * to be cleared. This is similar to wait_on_bit(), except also takes a
1155dd43ce2SIngo Molnar  * timeout parameter.
1165dd43ce2SIngo Molnar  *
1175dd43ce2SIngo Molnar  * Returned value will be zero if the bit was cleared before the
1185dd43ce2SIngo Molnar  * @timeout elapsed, or non-zero if the @timeout elapsed or process
1195dd43ce2SIngo Molnar  * received a signal and the mode permitted wakeup on that signal.
1205dd43ce2SIngo Molnar  */
1215dd43ce2SIngo Molnar static inline int
wait_on_bit_timeout(unsigned long * word,int bit,unsigned mode,unsigned long timeout)1225dd43ce2SIngo Molnar wait_on_bit_timeout(unsigned long *word, int bit, unsigned mode,
1235dd43ce2SIngo Molnar 		    unsigned long timeout)
1245dd43ce2SIngo Molnar {
1255dd43ce2SIngo Molnar 	might_sleep();
126*8238b457SMikulas Patocka 	if (!test_bit_acquire(bit, word))
1275dd43ce2SIngo Molnar 		return 0;
1285dd43ce2SIngo Molnar 	return out_of_line_wait_on_bit_timeout(word, bit,
1295dd43ce2SIngo Molnar 					       bit_wait_timeout,
1305dd43ce2SIngo Molnar 					       mode, timeout);
1315dd43ce2SIngo Molnar }
1325dd43ce2SIngo Molnar 
1335dd43ce2SIngo Molnar /**
1345dd43ce2SIngo Molnar  * wait_on_bit_action - wait for a bit to be cleared
1355dd43ce2SIngo Molnar  * @word: the word being waited on, a kernel virtual address
1365dd43ce2SIngo Molnar  * @bit: the bit of the word being waited on
1375dd43ce2SIngo Molnar  * @action: the function used to sleep, which may take special actions
1385dd43ce2SIngo Molnar  * @mode: the task state to sleep in
1395dd43ce2SIngo Molnar  *
1405dd43ce2SIngo Molnar  * Use the standard hashed waitqueue table to wait for a bit
1415dd43ce2SIngo Molnar  * to be cleared, and allow the waiting action to be specified.
1425dd43ce2SIngo Molnar  * This is like wait_on_bit() but allows fine control of how the waiting
1435dd43ce2SIngo Molnar  * is done.
1445dd43ce2SIngo Molnar  *
1455dd43ce2SIngo Molnar  * Returned value will be zero if the bit was cleared, or non-zero
1465dd43ce2SIngo Molnar  * if the process received a signal and the mode permitted wakeup
1475dd43ce2SIngo Molnar  * on that signal.
1485dd43ce2SIngo Molnar  */
1495dd43ce2SIngo Molnar static inline int
wait_on_bit_action(unsigned long * word,int bit,wait_bit_action_f * action,unsigned mode)1505dd43ce2SIngo Molnar wait_on_bit_action(unsigned long *word, int bit, wait_bit_action_f *action,
1515dd43ce2SIngo Molnar 		   unsigned mode)
1525dd43ce2SIngo Molnar {
1535dd43ce2SIngo Molnar 	might_sleep();
154*8238b457SMikulas Patocka 	if (!test_bit_acquire(bit, word))
1555dd43ce2SIngo Molnar 		return 0;
1565dd43ce2SIngo Molnar 	return out_of_line_wait_on_bit(word, bit, action, mode);
1575dd43ce2SIngo Molnar }
1585dd43ce2SIngo Molnar 
1595dd43ce2SIngo Molnar /**
1605dd43ce2SIngo Molnar  * wait_on_bit_lock - wait for a bit to be cleared, when wanting to set it
1615dd43ce2SIngo Molnar  * @word: the word being waited on, a kernel virtual address
1625dd43ce2SIngo Molnar  * @bit: the bit of the word being waited on
1635dd43ce2SIngo Molnar  * @mode: the task state to sleep in
1645dd43ce2SIngo Molnar  *
1655dd43ce2SIngo Molnar  * There is a standard hashed waitqueue table for generic use. This
1665dd43ce2SIngo Molnar  * is the part of the hashtable's accessor API that waits on a bit
1675dd43ce2SIngo Molnar  * when one intends to set it, for instance, trying to lock bitflags.
1685dd43ce2SIngo Molnar  * For instance, if one were to have waiters trying to set bitflag
1695dd43ce2SIngo Molnar  * and waiting for it to clear before setting it, one would call
1705dd43ce2SIngo Molnar  * wait_on_bit() in threads waiting to be able to set the bit.
1715dd43ce2SIngo Molnar  * One uses wait_on_bit_lock() where one is waiting for the bit to
1725dd43ce2SIngo Molnar  * clear with the intention of setting it, and when done, clearing it.
1735dd43ce2SIngo Molnar  *
1745dd43ce2SIngo Molnar  * Returns zero if the bit was (eventually) found to be clear and was
1755dd43ce2SIngo Molnar  * set.  Returns non-zero if a signal was delivered to the process and
1765dd43ce2SIngo Molnar  * the @mode allows that signal to wake the process.
1775dd43ce2SIngo Molnar  */
1785dd43ce2SIngo Molnar static inline int
wait_on_bit_lock(unsigned long * word,int bit,unsigned mode)1795dd43ce2SIngo Molnar wait_on_bit_lock(unsigned long *word, int bit, unsigned mode)
1805dd43ce2SIngo Molnar {
1815dd43ce2SIngo Molnar 	might_sleep();
1825dd43ce2SIngo Molnar 	if (!test_and_set_bit(bit, word))
1835dd43ce2SIngo Molnar 		return 0;
1845dd43ce2SIngo Molnar 	return out_of_line_wait_on_bit_lock(word, bit, bit_wait, mode);
1855dd43ce2SIngo Molnar }
1865dd43ce2SIngo Molnar 
1875dd43ce2SIngo Molnar /**
1885dd43ce2SIngo Molnar  * wait_on_bit_lock_io - wait for a bit to be cleared, when wanting to set it
1895dd43ce2SIngo Molnar  * @word: the word being waited on, a kernel virtual address
1905dd43ce2SIngo Molnar  * @bit: the bit of the word being waited on
1915dd43ce2SIngo Molnar  * @mode: the task state to sleep in
1925dd43ce2SIngo Molnar  *
1935dd43ce2SIngo Molnar  * Use the standard hashed waitqueue table to wait for a bit
1945dd43ce2SIngo Molnar  * to be cleared and then to atomically set it.  This is similar
1955dd43ce2SIngo Molnar  * to wait_on_bit(), but calls io_schedule() instead of schedule()
1965dd43ce2SIngo Molnar  * for the actual waiting.
1975dd43ce2SIngo Molnar  *
1985dd43ce2SIngo Molnar  * Returns zero if the bit was (eventually) found to be clear and was
1995dd43ce2SIngo Molnar  * set.  Returns non-zero if a signal was delivered to the process and
2005dd43ce2SIngo Molnar  * the @mode allows that signal to wake the process.
2015dd43ce2SIngo Molnar  */
2025dd43ce2SIngo Molnar static inline int
wait_on_bit_lock_io(unsigned long * word,int bit,unsigned mode)2035dd43ce2SIngo Molnar wait_on_bit_lock_io(unsigned long *word, int bit, unsigned mode)
2045dd43ce2SIngo Molnar {
2055dd43ce2SIngo Molnar 	might_sleep();
2065dd43ce2SIngo Molnar 	if (!test_and_set_bit(bit, word))
2075dd43ce2SIngo Molnar 		return 0;
2085dd43ce2SIngo Molnar 	return out_of_line_wait_on_bit_lock(word, bit, bit_wait_io, mode);
2095dd43ce2SIngo Molnar }
2105dd43ce2SIngo Molnar 
2115dd43ce2SIngo Molnar /**
2125dd43ce2SIngo Molnar  * wait_on_bit_lock_action - wait for a bit to be cleared, when wanting to set it
2135dd43ce2SIngo Molnar  * @word: the word being waited on, a kernel virtual address
2145dd43ce2SIngo Molnar  * @bit: the bit of the word being waited on
2155dd43ce2SIngo Molnar  * @action: the function used to sleep, which may take special actions
2165dd43ce2SIngo Molnar  * @mode: the task state to sleep in
2175dd43ce2SIngo Molnar  *
2185dd43ce2SIngo Molnar  * Use the standard hashed waitqueue table to wait for a bit
2195dd43ce2SIngo Molnar  * to be cleared and then to set it, and allow the waiting action
2205dd43ce2SIngo Molnar  * to be specified.
2215dd43ce2SIngo Molnar  * This is like wait_on_bit() but allows fine control of how the waiting
2225dd43ce2SIngo Molnar  * is done.
2235dd43ce2SIngo Molnar  *
2245dd43ce2SIngo Molnar  * Returns zero if the bit was (eventually) found to be clear and was
2255dd43ce2SIngo Molnar  * set.  Returns non-zero if a signal was delivered to the process and
2265dd43ce2SIngo Molnar  * the @mode allows that signal to wake the process.
2275dd43ce2SIngo Molnar  */
2285dd43ce2SIngo Molnar static inline int
wait_on_bit_lock_action(unsigned long * word,int bit,wait_bit_action_f * action,unsigned mode)2295dd43ce2SIngo Molnar wait_on_bit_lock_action(unsigned long *word, int bit, wait_bit_action_f *action,
2305dd43ce2SIngo Molnar 			unsigned mode)
2315dd43ce2SIngo Molnar {
2325dd43ce2SIngo Molnar 	might_sleep();
2335dd43ce2SIngo Molnar 	if (!test_and_set_bit(bit, word))
2345dd43ce2SIngo Molnar 		return 0;
2355dd43ce2SIngo Molnar 	return out_of_line_wait_on_bit_lock(word, bit, action, mode);
2365dd43ce2SIngo Molnar }
2375dd43ce2SIngo Molnar 
2386b2bb726SPeter Zijlstra extern void init_wait_var_entry(struct wait_bit_queue_entry *wbq_entry, void *var, int flags);
2396b2bb726SPeter Zijlstra extern void wake_up_var(void *var);
2406b2bb726SPeter Zijlstra extern wait_queue_head_t *__var_waitqueue(void *p);
2416b2bb726SPeter Zijlstra 
2426b2bb726SPeter Zijlstra #define ___wait_var_event(var, condition, state, exclusive, ret, cmd)	\
2436b2bb726SPeter Zijlstra ({									\
2446b2bb726SPeter Zijlstra 	__label__ __out;						\
2456b2bb726SPeter Zijlstra 	struct wait_queue_head *__wq_head = __var_waitqueue(var);	\
2466b2bb726SPeter Zijlstra 	struct wait_bit_queue_entry __wbq_entry;			\
2476b2bb726SPeter Zijlstra 	long __ret = ret; /* explicit shadow */				\
2486b2bb726SPeter Zijlstra 									\
2496b2bb726SPeter Zijlstra 	init_wait_var_entry(&__wbq_entry, var,				\
2506b2bb726SPeter Zijlstra 			    exclusive ? WQ_FLAG_EXCLUSIVE : 0);		\
2516b2bb726SPeter Zijlstra 	for (;;) {							\
2526b2bb726SPeter Zijlstra 		long __int = prepare_to_wait_event(__wq_head,		\
2536b2bb726SPeter Zijlstra 						   &__wbq_entry.wq_entry, \
2546b2bb726SPeter Zijlstra 						   state);		\
2556b2bb726SPeter Zijlstra 		if (condition)						\
2566b2bb726SPeter Zijlstra 			break;						\
2576b2bb726SPeter Zijlstra 									\
2586b2bb726SPeter Zijlstra 		if (___wait_is_interruptible(state) && __int) {		\
2596b2bb726SPeter Zijlstra 			__ret = __int;					\
2606b2bb726SPeter Zijlstra 			goto __out;					\
2616b2bb726SPeter Zijlstra 		}							\
2626b2bb726SPeter Zijlstra 									\
2636b2bb726SPeter Zijlstra 		cmd;							\
2646b2bb726SPeter Zijlstra 	}								\
2656b2bb726SPeter Zijlstra 	finish_wait(__wq_head, &__wbq_entry.wq_entry);			\
2666b2bb726SPeter Zijlstra __out:	__ret;								\
2676b2bb726SPeter Zijlstra })
2686b2bb726SPeter Zijlstra 
2696b2bb726SPeter Zijlstra #define __wait_var_event(var, condition)				\
2706b2bb726SPeter Zijlstra 	___wait_var_event(var, condition, TASK_UNINTERRUPTIBLE, 0, 0,	\
2716b2bb726SPeter Zijlstra 			  schedule())
2726b2bb726SPeter Zijlstra 
2736b2bb726SPeter Zijlstra #define wait_var_event(var, condition)					\
2746b2bb726SPeter Zijlstra do {									\
2756b2bb726SPeter Zijlstra 	might_sleep();							\
2766b2bb726SPeter Zijlstra 	if (condition)							\
2776b2bb726SPeter Zijlstra 		break;							\
2786b2bb726SPeter Zijlstra 	__wait_var_event(var, condition);				\
2796b2bb726SPeter Zijlstra } while (0)
2806b2bb726SPeter Zijlstra 
2816b2bb726SPeter Zijlstra #define __wait_var_event_killable(var, condition)			\
2826b2bb726SPeter Zijlstra 	___wait_var_event(var, condition, TASK_KILLABLE, 0, 0,		\
2836b2bb726SPeter Zijlstra 			  schedule())
2846b2bb726SPeter Zijlstra 
2856b2bb726SPeter Zijlstra #define wait_var_event_killable(var, condition)				\
2866b2bb726SPeter Zijlstra ({									\
2876b2bb726SPeter Zijlstra 	int __ret = 0;							\
2886b2bb726SPeter Zijlstra 	might_sleep();							\
2896b2bb726SPeter Zijlstra 	if (!(condition))						\
2906b2bb726SPeter Zijlstra 		__ret = __wait_var_event_killable(var, condition);	\
2916b2bb726SPeter Zijlstra 	__ret;								\
2926b2bb726SPeter Zijlstra })
2936b2bb726SPeter Zijlstra 
2946b2bb726SPeter Zijlstra #define __wait_var_event_timeout(var, condition, timeout)		\
2956b2bb726SPeter Zijlstra 	___wait_var_event(var, ___wait_cond_timeout(condition),		\
2966b2bb726SPeter Zijlstra 			  TASK_UNINTERRUPTIBLE, 0, timeout,		\
2976b2bb726SPeter Zijlstra 			  __ret = schedule_timeout(__ret))
2986b2bb726SPeter Zijlstra 
2996b2bb726SPeter Zijlstra #define wait_var_event_timeout(var, condition, timeout)			\
3006b2bb726SPeter Zijlstra ({									\
3016b2bb726SPeter Zijlstra 	long __ret = timeout;						\
3026b2bb726SPeter Zijlstra 	might_sleep();							\
3036b2bb726SPeter Zijlstra 	if (!___wait_cond_timeout(condition))				\
3046b2bb726SPeter Zijlstra 		__ret = __wait_var_event_timeout(var, condition, timeout); \
3056b2bb726SPeter Zijlstra 	__ret;								\
3066b2bb726SPeter Zijlstra })
3076b2bb726SPeter Zijlstra 
308a49294eaSDavid Howells #define __wait_var_event_interruptible(var, condition)			\
309a49294eaSDavid Howells 	___wait_var_event(var, condition, TASK_INTERRUPTIBLE, 0, 0,	\
310a49294eaSDavid Howells 			  schedule())
311a49294eaSDavid Howells 
312a49294eaSDavid Howells #define wait_var_event_interruptible(var, condition)			\
313a49294eaSDavid Howells ({									\
314a49294eaSDavid Howells 	int __ret = 0;							\
315a49294eaSDavid Howells 	might_sleep();							\
316a49294eaSDavid Howells 	if (!(condition))						\
317a49294eaSDavid Howells 		__ret = __wait_var_event_interruptible(var, condition);	\
318a49294eaSDavid Howells 	__ret;								\
319a49294eaSDavid Howells })
320a49294eaSDavid Howells 
3218236b0aeSTetsuo Handa /**
3228236b0aeSTetsuo Handa  * clear_and_wake_up_bit - clear a bit and wake up anyone waiting on that bit
3238236b0aeSTetsuo Handa  *
3248236b0aeSTetsuo Handa  * @bit: the bit of the word being waited on
3258236b0aeSTetsuo Handa  * @word: the word being waited on, a kernel virtual address
3268236b0aeSTetsuo Handa  *
3278236b0aeSTetsuo Handa  * You can use this helper if bitflags are manipulated atomically rather than
3288236b0aeSTetsuo Handa  * non-atomically under a lock.
3298236b0aeSTetsuo Handa  */
clear_and_wake_up_bit(int bit,void * word)3308236b0aeSTetsuo Handa static inline void clear_and_wake_up_bit(int bit, void *word)
3318236b0aeSTetsuo Handa {
3328236b0aeSTetsuo Handa 	clear_bit_unlock(bit, word);
3338236b0aeSTetsuo Handa 	/* See wake_up_bit() for which memory barrier you need to use. */
3348236b0aeSTetsuo Handa 	smp_mb__after_atomic();
3358236b0aeSTetsuo Handa 	wake_up_bit(word, bit);
3368236b0aeSTetsuo Handa }
3378236b0aeSTetsuo Handa 
3385dd43ce2SIngo Molnar #endif /* _LINUX_WAIT_BIT_H */
339