blob: ef3901238ddd5369f55e79c0314e5027c561bbf6 [file] [log] [blame]
David Sterba602cbe92019-08-21 18:48:25 +02001/* SPDX-License-Identifier: GPL-2.0 */
2
3#ifndef BTRFS_MISC_H
4#define BTRFS_MISC_H
5
6#include <linux/sched.h>
7#include <linux/wait.h>
8
9#define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len))
10
11static inline void cond_wake_up(struct wait_queue_head *wq)
12{
13 /*
14 * This implies a full smp_mb barrier, see comments for
15 * waitqueue_active why.
16 */
17 if (wq_has_sleeper(wq))
18 wake_up(wq);
19}
20
21static inline void cond_wake_up_nomb(struct wait_queue_head *wq)
22{
23 /*
24 * Special case for conditional wakeup where the barrier required for
25 * waitqueue_active is implied by some of the preceding code. Eg. one
26 * of such atomic operations (atomic_dec_and_return, ...), or a
27 * unlock/lock sequence, etc.
28 */
29 if (waitqueue_active(wq))
30 wake_up(wq);
31}
32
33#endif