mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-21 08:29:41 +00:00
committed by
Norman Feske
parent
fb2998e534
commit
ff29f85cc9
@ -23,6 +23,7 @@ namespace Genode {
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
addr_t _next;
|
||||||
Bit_array<WORDS> _array;
|
Bit_array<WORDS> _array;
|
||||||
|
|
||||||
void _reserve(addr_t bit_start, size_t const num_cap)
|
void _reserve(addr_t bit_start, size_t const num_cap)
|
||||||
@ -34,32 +35,40 @@ namespace Genode {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Bit_allocator() : _next(0) { }
|
||||||
|
|
||||||
addr_t alloc(size_t const num_log2)
|
addr_t alloc(size_t const num_log2)
|
||||||
{
|
{
|
||||||
addr_t const step = 1UL << num_log2;
|
addr_t const step = 1UL << num_log2;
|
||||||
addr_t i = 0;
|
addr_t max = ~0UL;
|
||||||
|
|
||||||
try {
|
do
|
||||||
/*
|
{
|
||||||
* Throws exception if array is * accessed outside bounds
|
try
|
||||||
*/
|
{
|
||||||
while (true) {
|
/* throws exception if array is accessed outside bounds */
|
||||||
if (_array.get(i, step)) {
|
for (addr_t i = _next & ~(step - 1); i < max; i += step) {
|
||||||
i += step;
|
if (_array.get(i, step))
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
_array.set(i, step);
|
_array.set(i, step);
|
||||||
|
_next = i + step;
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
} catch (Bit_array_invalid_index_access) {}
|
} catch (Bit_array_invalid_index_access) { }
|
||||||
|
|
||||||
|
max = _next;
|
||||||
|
_next = 0;
|
||||||
|
|
||||||
|
} while (max != 0);
|
||||||
|
|
||||||
throw Bit_array_out_of_indexes();
|
throw Bit_array_out_of_indexes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void free(addr_t const bit_start,
|
void free(addr_t const bit_start, size_t const num_log2)
|
||||||
size_t const num_log2)
|
|
||||||
{
|
{
|
||||||
_array.clear(bit_start, 1UL << num_log2);
|
_array.clear(bit_start, 1UL << num_log2);
|
||||||
|
_next = bit_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
2
base-nova/src/base/env/cap_sel_alloc.cc
vendored
2
base-nova/src/base/env/cap_sel_alloc.cc
vendored
@ -48,7 +48,7 @@ void Cap_selector_allocator::free(addr_t cap, size_t num_caps_log2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Cap_selector_allocator::Cap_selector_allocator()
|
Cap_selector_allocator::Cap_selector_allocator() : Bit_allocator()
|
||||||
{
|
{
|
||||||
/* initialize lock */
|
/* initialize lock */
|
||||||
alloc_lock();
|
alloc_lock();
|
||||||
|
Reference in New Issue
Block a user