diff options
author | Enrico Loparco (eloparco) <eloparco@cisco.com> | 2021-04-05 12:10:45 +0200 |
---|---|---|
committer | Enrico Loparco (eloparco) <eloparco@cisco.com> | 2021-06-24 09:20:11 +0200 |
commit | 1c37763975af0a6c89a9089aa606155227e67d41 (patch) | |
tree | 4722a4abeda4cdf188a512a6508d0d79d1fda330 /hicn-light/src/hicn/base/bitmap.h | |
parent | 229385955109b866a23c4ac2aa03d4d11044c39d (diff) |
[HICN-555, HICN-556] Add loop utility function and fix memory bug in bitmap
A helper function is added to the loop class to allow loop exit after empty event queue. This function is used when running tests.
Signed-off-by: Enrico Loparco (eloparco) <eloparco@cisco.com>
Change-Id: I7bbab32a7d7f53365439f0fba2b9a030d34ac823
Diffstat (limited to 'hicn-light/src/hicn/base/bitmap.h')
-rw-r--r-- | hicn-light/src/hicn/base/bitmap.h | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/hicn-light/src/hicn/base/bitmap.h b/hicn-light/src/hicn/base/bitmap.h index 1159806c8..908b28d87 100644 --- a/hicn-light/src/hicn/base/bitmap.h +++ b/hicn-light/src/hicn/base/bitmap.h @@ -100,16 +100,27 @@ bitmap_get(const bitmap_t * bitmap, off_t i) * * @return bool */ +#define bitmap_set(bitmap, i) \ + _bitmap_set((bitmap_t**)&bitmap, i) + +/* + * @brief Returns whether the i-th bit is unset (equal to 0) in a bitmap (helper). + * + * @param[in] bitmap The bitmap to access. + * @param[in] i The bit position. + * + * @return bool + */ static inline int -bitmap_set(bitmap_t * bitmap, off_t i) +_bitmap_set(bitmap_t ** bitmap, off_t i) { - if (bitmap_ensure_pos(&bitmap, i) < 0) + if (bitmap_ensure_pos(bitmap, i) < 0) return -1; size_t offset = i / BITMAP_WIDTH(bitmap); size_t pos = i % BITMAP_WIDTH(bitmap); size_t shift = BITMAP_WIDTH(bitmap) - pos - 1; - bitmap[offset] |= 1ul << shift; + (*bitmap)[offset] |= 1ul << shift; return 0; } |