diff options
-rw-r--r-- | rts/adjustor/AdjustorPool.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/rts/adjustor/AdjustorPool.c b/rts/adjustor/AdjustorPool.c index 9458c67246..146afc5b40 100644 --- a/rts/adjustor/AdjustorPool.c +++ b/rts/adjustor/AdjustorPool.c @@ -167,20 +167,6 @@ new_adjustor_pool( return pool; } -/* Return the index of the first unset bit of the given bitmap or - * length_in_bits. */ -static size_t -bitmap_first_unset(uint8_t *bitmap, size_t length_in_bits, size_t start_idx) -{ - for (size_t i = start_idx; i < length_in_bits; i += 8) { - uint8_t x = bitmap[i / 8]; - if (x != 0xff) { - return i + __builtin_clz(~x); - } - } - return length_in_bits; -} - static void bitmap_set(uint8_t *bitmap, size_t idx, bool value) { @@ -202,6 +188,19 @@ bitmap_get(uint8_t *bitmap, size_t idx) return bitmap[word_n] & bit; } +/* Return the index of the first unset bit of the given bitmap or + * length_in_bits if all bits are set. */ +static size_t +bitmap_first_unset(uint8_t *bitmap, size_t length_in_bits, size_t start_idx) +{ + for (size_t i = start_idx; i < length_in_bits; i ++) { + if (bitmap_get(bitmap, i) == 0) { + return i; + } + } + return length_in_bits; +} + static void * get_context(struct AdjustorChunk *chunk, size_t slot_idx) { @@ -224,6 +223,7 @@ alloc_adjustor(struct AdjustorPool *pool, void *context) chunk = pool->free_list; slot_idx = chunk->first_free; ASSERT(slot_idx < pool->chunk_slots); + ASSERT(bitmap_get(chunk->slot_bitmap, slot_idx) == 0); bitmap_set(chunk->slot_bitmap, slot_idx, 1); // advance first_free |