diff options
| author | Peter Xu <peterx@redhat.com> | 2018-08-22 03:19:56 -0400 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2018-08-22 10:48:36 -0400 |
| commit | 07a262cc7c586e3f385a61b8870b0913bf31309a (patch) | |
| tree | 811be68591ad09d41e9a898c5ae95912d8491392 | |
| parent | 024d83cadc6b2af027e473720f3c3da97496c318 (diff) | |
tools: introduce test_and_clear_bit
We have test_and_set_bit but not test_and_clear_bit. Add it.
Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
| -rw-r--r-- | tools/include/linux/bitmap.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/include/linux/bitmap.h b/tools/include/linux/bitmap.h index 63440cc8d618..e63662db131b 100644 --- a/tools/include/linux/bitmap.h +++ b/tools/include/linux/bitmap.h | |||
| @@ -97,6 +97,23 @@ static inline int test_and_set_bit(int nr, unsigned long *addr) | |||
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | /** | 99 | /** |
| 100 | * test_and_clear_bit - Clear a bit and return its old value | ||
| 101 | * @nr: Bit to clear | ||
| 102 | * @addr: Address to count from | ||
| 103 | */ | ||
| 104 | static inline int test_and_clear_bit(int nr, unsigned long *addr) | ||
| 105 | { | ||
| 106 | unsigned long mask = BIT_MASK(nr); | ||
| 107 | unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); | ||
| 108 | unsigned long old; | ||
| 109 | |||
| 110 | old = *p; | ||
| 111 | *p = old & ~mask; | ||
| 112 | |||
| 113 | return (old & mask) != 0; | ||
| 114 | } | ||
| 115 | |||
| 116 | /** | ||
| 100 | * bitmap_alloc - Allocate bitmap | 117 | * bitmap_alloc - Allocate bitmap |
| 101 | * @nbits: Number of bits | 118 | * @nbits: Number of bits |
| 102 | */ | 119 | */ |
