diff options
Diffstat (limited to 'lib/bitfield.h')
-rw-r--r-- | lib/bitfield.h | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/bitfield.h b/lib/bitfield.h index 4ff9c7fb2..1e0b54731 100644 --- a/lib/bitfield.h +++ b/lib/bitfield.h @@ -78,12 +78,27 @@ typedef unsigned int word_t; bf_set_bit(v, id); \ } while (0) -/** +/* + * allocate and assign 0th bit in the bitfiled. + */ +#define bf_assign_zero_index(v) \ + do { \ + int id = 0; \ + bf_assign_index(v, id); \ + } while (0) + +/* * return an id to bitfield v */ #define bf_release_index(v, id) \ (v).data[bf_index(id)] &= ~(1 << (bf_offset(id))) +/* + * return 0th index back to bitfield + */ +#define bf_release_zero_index(v) \ + bf_release_index(v, 0) + #define bf_index(b) ((b) / WORD_SIZE) #define bf_offset(b) ((b) % WORD_SIZE) @@ -118,4 +133,15 @@ typedef unsigned int word_t; (b) += (w * WORD_SIZE); \ } while (0) +/* + * Free the allocated memory for data + * @v: an instance of bitfield_t struct. + */ +#define bf_free(v) \ + do { \ + if ((v).data) { \ + free((v).data); \ + } \ + } while (0) + #endif |