From 03062b83b61691508c30dcc43b890f2e02183345 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 14 Mar 2018 12:59:54 +0100 Subject: [PATCH] nic_router: alloc specific port at port allocators Methods to allocate a specific port at Port_allocator and Port_allocator_guard. Ref #2670 --- .../src/server/nic_router/port_allocator.cc | 22 +++++++++++++++++++ .../os/src/server/nic_router/port_allocator.h | 6 +++++ 2 files changed, 28 insertions(+) diff --git a/repos/os/src/server/nic_router/port_allocator.cc b/repos/os/src/server/nic_router/port_allocator.cc index 9597080f6b..8c955705e3 100644 --- a/repos/os/src/server/nic_router/port_allocator.cc +++ b/repos/os/src/server/nic_router/port_allocator.cc @@ -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::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); diff --git a/repos/os/src/server/nic_router/port_allocator.h b/repos/os/src/server/nic_router/port_allocator.h index 71f54acfa7..4592f64706 100644 --- a/repos/os/src/server/nic_router/port_allocator.h +++ b/repos/os/src/server/nic_router/port_allocator.h @@ -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);