diff --git a/src/libutil/pool.hh b/src/libutil/pool.hh index bc71083e9..2f6d30130 100644 --- a/src/libutil/pool.hh +++ b/src/libutil/pool.hh @@ -108,19 +108,6 @@ public: Handle(Pool & pool, std::shared_ptr r) : pool(pool), r(r) { } - void drop(bool stillValid) - { - { - auto state_(pool.state.lock()); - if (stillValid) - state_->idle.emplace_back(std::move(r)); - assert(state_->inUse); - state_->inUse--; - } - pool.wakeup.notify_one(); - r = nullptr; - } - public: Handle(Handle && h) : pool(h.pool), r(h.r) { h.r.reset(); } @@ -128,13 +115,15 @@ public: ~Handle() { - if (r) - drop(std::uncaught_exceptions() == 0); - } - - void release() - { - drop(true); + if (!r) return; + { + auto state_(pool.state.lock()); + if (!std::uncaught_exceptions()) + state_->idle.push_back(ref(r)); + assert(state_->inUse); + state_->inUse--; + } + pool.wakeup.notify_one(); } R * operator -> () { return &*r; }