mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-31 00:24:51 +00:00
bit_allocator: alloc specific block of bits
Method to try to allocate specific bits of the Bit_allocator_dynamic. Ref #2670
This commit is contained in:
parent
72036d3f88
commit
ff7c378ff9
@ -52,6 +52,7 @@ class Genode::Bit_allocator
|
||||
public:
|
||||
|
||||
class Out_of_indices : Exception {};
|
||||
class Range_conflict : Exception {};
|
||||
|
||||
Bit_allocator() { _reserve(BITS, BITS_ALIGNED - BITS); }
|
||||
Bit_allocator(const Bit_allocator & o) : _array(o._array) { }
|
||||
@ -82,6 +83,26 @@ class Genode::Bit_allocator
|
||||
throw Out_of_indices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate specific block of bits
|
||||
*
|
||||
* \param first_bit desired address of block
|
||||
* \param num_log2 2-based logarithm of size of block
|
||||
*
|
||||
* \throw Range_conflict
|
||||
* \throw Array::Invalid_index_access
|
||||
*/
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user