mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 18:56:29 +00:00
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:
parent
e0081cfc29
commit
03062b83b6
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user