aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light')
-rw-r--r--hicn-light/src/hicn/base/bitmap.h10
-rw-r--r--hicn-light/src/hicn/base/pool.c6
-rw-r--r--hicn-light/src/hicn/base/pool.h6
-rw-r--r--hicn-light/src/hicn/base/test/test-pool.cc2
4 files changed, 11 insertions, 13 deletions
diff --git a/hicn-light/src/hicn/base/bitmap.h b/hicn-light/src/hicn/base/bitmap.h
index ebc3dddbb..1159806c8 100644
--- a/hicn-light/src/hicn/base/bitmap.h
+++ b/hicn-light/src/hicn/base/bitmap.h
@@ -59,10 +59,10 @@ typedef uint_fast32_t bitmap_t;
*/
static inline
int
-bitmap_ensure_pos(bitmap_t * bitmap, off_t pos)
+bitmap_ensure_pos(bitmap_t ** bitmap, off_t pos)
{
- size_t offset = pos / BITMAP_WIDTH(bitmap);
- return vector_ensure_pos(bitmap, offset);
+ size_t offset = pos / BITMAP_WIDTH(*bitmap);
+ return vector_ensure_pos(*bitmap, offset);
}
/**
@@ -104,7 +104,7 @@ static inline
int
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);
@@ -117,7 +117,7 @@ static inline
int
bitmap_unset(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);
diff --git a/hicn-light/src/hicn/base/pool.c b/hicn-light/src/hicn/base/pool.c
index cb650b9e5..a7c50963d 100644
--- a/hicn-light/src/hicn/base/pool.c
+++ b/hicn-light/src/hicn/base/pool.c
@@ -116,7 +116,7 @@ _pool_resize(void ** pool_ptr, size_t elt_size)
vector_len(ph->free_indices) = old_size;
/* We also need to update the bitmap */
- bitmap_ensure_pos(ph->free_bitmap, new_size - 1);
+ bitmap_ensure_pos(&(ph->free_bitmap), new_size - 1);
bitmap_set_range(ph->free_bitmap, old_size, new_size - 1);
/* Reassign pool pointer */
@@ -143,8 +143,8 @@ _pool_get(void ** pool_ptr, void ** elt, size_t elt_size)
off_t free_id = ph->free_indices[l - 1];
vector_len(ph->free_indices)--;
bitmap_unset(ph->free_bitmap, free_id);
- *elt = *pool_ptr + free_id;
- memset(*elt, 0, sizeof(elt));
+ *elt = *pool_ptr + free_id * elt_size;
+ memset(*elt, 0, elt_size);
return free_id;
}
diff --git a/hicn-light/src/hicn/base/pool.h b/hicn-light/src/hicn/base/pool.h
index 57172192b..85117c452 100644
--- a/hicn-light/src/hicn/base/pool.h
+++ b/hicn-light/src/hicn/base/pool.h
@@ -53,7 +53,7 @@ typedef struct {
size_t elt_size;
size_t alloc_size;
size_t max_size;
- uint_fast32_t * free_bitmap; /* bitmap of free indices */
+ bitmap_t * free_bitmap; /* bitmap of free indices */
off_t * free_indices; /* vector of free indices */
} pool_hdr_t;
@@ -148,7 +148,7 @@ void _pool_put(void ** pool, void ** elt, size_t elt_size);
* NOTES:
* - The memory chunk is cleared upon attribution
*/
-#define pool_get(pool, elt) _pool_get((void**)&pool, (void**)&elt, sizeof(elt))
+#define pool_get(pool, elt) _pool_get((void**)&pool, (void**)&elt, sizeof(*elt))
/**
* @brief Put an element back into the pool data structure.
@@ -156,7 +156,7 @@ void _pool_put(void ** pool, void ** elt, size_t elt_size);
* @param[in] pool The pool data structure to use.
* @param[in] elt The pool element to put back.
*/
-#define pool_put(pool, elt) _pool_put((void**)&pool, (void**)&elt, sizeof(elt))
+#define pool_put(pool, elt) _pool_put((void**)&pool, (void**)&elt, sizeof(*elt))
/**
* @brief Validate a pool element by index.
diff --git a/hicn-light/src/hicn/base/test/test-pool.cc b/hicn-light/src/hicn/base/test/test-pool.cc
index f87ff65dd..e5df191ea 100644
--- a/hicn-light/src/hicn/base/test/test-pool.cc
+++ b/hicn-light/src/hicn/base/test/test-pool.cc
@@ -155,8 +155,6 @@ TEST_F(PoolTest, PoolPut)
pool_free(pool);
}
-// TODO: this test fails, there is a problem when N = n*64
-// (i.e. when a bitmap reallocation occurs)
TEST_F(PoolTest, PoolGetForceBitmapRealloc)
{
const int N = 64;