nic_router: alloc specific port at port allocators

Methods to allocate a specific port at Port_allocator and
Port_allocator_guard.

Ref #2670
This commit is contained in:
Martin Stein 2018-03-14 12:59:54 +01:00 committed by Christian Helmuth
parent e0081cfc29
commit 03062b83b6
2 changed files with 28 additions and 0 deletions

View File

@ -26,6 +26,18 @@ bool Net::dynamic_port(Port const port)
}
/********************
** Port_allocator **
********************/
void Net::Port_allocator::alloc(Port const port)
{
try { _alloc.alloc_addr(port.value - FIRST); }
catch (Genode::Bit_allocator<COUNT>::Range_conflict) {
throw Allocation_conflict(); }
}
/**************************
** Port_allocator_guard **
**************************/
@ -41,6 +53,16 @@ Port Port_allocator_guard::alloc()
}
void Port_allocator_guard::alloc(Port const port)
{
if (_used == _max) {
throw Out_of_indices(); }
_port_alloc.alloc(port);
_used++;
}
void Port_allocator_guard::free(Port const port)
{
_port_alloc.free(port);

View File

@ -42,8 +42,12 @@ class Net::Port_allocator
public:
struct Allocation_conflict : Genode::Exception { };
Port alloc() { return Port(_alloc.alloc() + FIRST); }
void alloc(Port const port);
void free(Port const port) { _alloc.free(port.value - FIRST); }
};
@ -62,6 +66,8 @@ class Net::Port_allocator_guard
Port alloc();
void alloc(Port const port);
void free(Port const port);
Port_allocator_guard(Port_allocator & port_alloc, unsigned const max);