From d5f645ee69c784d0f8bad9f30cccc3560ae4f0b2 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 7 Mar 2018 13:56:52 +0100 Subject: [PATCH] nic_router: destroy_each for list wrapper List method to destruct and deallocate each item of a list. Ref #2670 --- repos/os/src/server/nic_router/list.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/repos/os/src/server/nic_router/list.h b/repos/os/src/server/nic_router/list.h index 64bc2c2e31..d49bbebd08 100644 --- a/repos/os/src/server/nic_router/list.h +++ b/repos/os/src/server/nic_router/list.h @@ -16,23 +16,33 @@ /* Genode includes */ #include +#include + +namespace Net { template class List; } -namespace Net { - template class List; -} template struct Net::List : Genode::List { + using Base = Genode::List; + template void for_each(FUNC && functor) { - for (LT * elem = Genode::List::first(); elem; - elem = elem->Genode::List::Element::next()) + for (LT * elem = Base::first(); elem; + elem = elem->Base::Element::next()) { functor(*elem); } } + + void destroy_each(Genode::Deallocator &dealloc) + { + while (LT *elem = Base::first()) { + Base::remove(elem); + destroy(dealloc, elem); + } + } }; #endif /* _LIST_H_ */