nic_router: alloc specific bits at bit allocator

Method to allocate specific bits at a Bit_allocator_dynamic

Ref #2670
This commit is contained in:
Martin Stein 2018-03-15 13:29:13 +01:00 committed by Christian Helmuth
parent 03062b83b6
commit 119b9f9c2c

View File

@ -179,6 +179,7 @@ class Genode::Bit_allocator_dynamic
public:
struct Out_of_indices : Exception { };
struct Range_conflict : Exception { };
addr_t alloc(size_t const num_log2 = 0)
{
@ -206,6 +207,17 @@ class Genode::Bit_allocator_dynamic
throw Out_of_indices();
}
void alloc_addr(addr_t const bit_start, size_t const num_log2 = 0)
{
addr_t const step = 1UL << num_log2;
if (_array.get(bit_start, step))
throw Range_conflict();
_array.set(bit_start, step);
_next = bit_start + step;
return;
}
void free(addr_t const bit_start, size_t const num_log2 = 0)
{
_array.clear(bit_start, 1UL << num_log2);