Skip to content

Commit

Permalink
tools: introduce test_and_clear_bit
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Peter Xu authored and Paolo Bonzini committed Aug 22, 2018
1 parent 024d83c commit 07a262c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/include/linux/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ static inline int test_and_set_bit(int nr, unsigned long *addr)
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
* @nbits: Number of bits
Expand Down

0 comments on commit 07a262c

Please sign in to comment.