From 528ea5fffe54db351970fa187c69862814fe358c Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 19 Jan 2024 14:44:37 +0100 Subject: [PATCH] pool: add clear Signed-off-by: Simon Rozman --- include/stdex/pool.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/stdex/pool.hpp b/include/stdex/pool.hpp index 10a675327..59ed7dfe6 100644 --- a/include/stdex/pool.hpp +++ b/include/stdex/pool.hpp @@ -87,5 +87,18 @@ namespace stdex const std::lock_guard guard(ne.lock); ne.list.push_front(std::move(r)); } + + /// + /// Removes all items from the pool + /// + void clear() + { + const std::lock_guard guard_m(m_mutex); + for (auto& ne : m_available) { + const std::lock_guard guard_l(ne.second.lock); + while (!ne.second.list.empty()) + ne.second.list.pop_front(); + } + } }; } \ No newline at end of file