summaryrefslogtreecommitdiffstats
path: root/tools/include
diff options
context:
space:
mode:
authorPeter Xu <peterx@redhat.com>2018-08-22 15:19:56 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2018-08-22 16:48:36 +0200
commit07a262cc7c586e3f385a61b8870b0913bf31309a (patch)
tree811be68591ad09d41e9a898c5ae95912d8491392 /tools/include
parent024d83cadc6b2af027e473720f3c3da97496c318 (diff)
downloadlinux-07a262cc7c586e3f385a61b8870b0913bf31309a.tar.bz2
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>
Diffstat (limited to 'tools/include')
-rw-r--r--tools/include/linux/bitmap.h17
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)
}
/**
+ * test_and_clear_bit - Clear a bit and return its old value
+ * @nr: Bit to clear
+ * @addr: Address to count from
+ */
+static inline int test_and_clear_bit(int nr, unsigned long *addr)
+{
+ unsigned long mask = BIT_MASK(nr);
+ unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr);
+ unsigned long old;
+
+ old = *p;
+ *p = old & ~mask;
+
+ return (old & mask) != 0;
+}
+
+/**
* bitmap_alloc - Allocate bitmap
* @nbits: Number of bits
*/