Commit 07a262cc authored by Peter Xu's avatar Peter Xu Committed by Paolo Bonzini

tools: introduce test_and_clear_bit

We have test_and_set_bit but not test_and_clear_bit.  Add it.
Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 024d83ca
...@@ -96,6 +96,23 @@ static inline int test_and_set_bit(int nr, unsigned long *addr) ...@@ -96,6 +96,23 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
return (old & mask) != 0; return (old & mask) != 0;
} }
/**
* 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 * bitmap_alloc - Allocate bitmap
* @nbits: Number of bits * @nbits: Number of bits
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment