summaryrefslogtreecommitdiffstats
path: root/lib/bitfield.h
diff options
context:
space:
mode:
authorvivek <vivek@cumulusnetworks.com>2017-05-15 07:18:26 +0200
committervivek <vivek@cumulusnetworks.com>2017-05-25 19:20:03 +0200
commit4e9da20145b4e53d063d2d15596fb1839e6740e3 (patch)
tree4b8709e3ad16aa3d37b5670934275935eee401b5 /lib/bitfield.h
parentlib: Macro for number of entries in hash table (diff)
downloadfrr-4e9da20145b4e53d063d2d15596fb1839e6740e3.tar.xz
frr-4e9da20145b4e53d063d2d15596fb1839e6740e3.zip
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>
Diffstat (limited to 'lib/bitfield.h')
-rw-r--r--lib/bitfield.h28
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