mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-29 14:40:47 +00:00
lib: Additional APIs in bitfield library
Added APIs to: a) pre-assign 0th bit in the bitfield b) free 0th bit in the bitfield c) free the allocated bitfield data Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com> Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
This commit is contained in:
parent
8234a9875b
commit
4e9da20145
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user