base: let bit allocator use fine-grained sizes

Ref #1588
This commit is contained in:
Stefan Kalkowski
2015-06-25 16:24:42 +02:00
committed by Christian Helmuth
parent 6552d47e60
commit b856bfdfcd
2 changed files with 33 additions and 24 deletions

View File

@ -25,8 +25,17 @@ class Genode::Bit_allocator
{
protected:
addr_t _next;
Bit_array<BITS> _array;
enum {
BITS_PER_BYTE = 8UL,
BITS_PER_WORD = sizeof(addr_t) * BITS_PER_BYTE,
BITS_ALIGNED = (BITS + BITS_PER_WORD - 1UL)
& ~(BITS_PER_WORD - 1UL),
};
using Array = Bit_array<BITS_ALIGNED>;
addr_t _next;
Array _array;
/**
* Reserve consecutive number of bits
@ -44,7 +53,8 @@ class Genode::Bit_allocator
class Out_of_indices : Exception {};
Bit_allocator() : _next(0) { }
Bit_allocator() : _next(0) {
_reserve(BITS, BITS_ALIGNED - BITS); }
addr_t alloc(size_t const num_log2 = 0)
{
@ -62,7 +72,7 @@ class Genode::Bit_allocator
_next = i + step;
return i;
}
} catch (typename Bit_array<BITS>::Invalid_index_access) { }
} catch (typename Array::Invalid_index_access) { }
max = _next;
_next = 0;