From f7a9fbd0cf962ad4359124ac0383aea9e22a2bbc Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Sat, 18 Apr 2026 17:51:29 -0400 Subject: [PATCH] thread_pool: replace goto claimed with explicit bool in claim path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The RAII-guarded locks at function top survive the goto correctly, but the pattern reads awkwardly — reviewers have to verify that nothing in the claimed path relies on state that the goto skipped over. Use a bool flag and a straight-line fall-through instead. No behavior change. --- vendored/libfuse/include/thread_pool.hpp | 32 +++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index d87cd415..ea28693c 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -887,29 +887,31 @@ ThreadPool::_try_claim_and_remove_self(pthread_t t_) // Try to claim a pending removal. std::size_t count = _remove_count.load(std::memory_order_relaxed); + bool claimed = false; while(count > 0) { if(_remove_count.compare_exchange_weak(count,count - 1, std::memory_order_acq_rel)) - goto claimed; + { + claimed = true; + break; + } } - return false; + if(!claimed) + return false; -claimed: // Safety floor: never remove the last thread. Use the same // min_allowed logic as _remove_thread_scaling_locked. - { - std::size_t min_allowed = 1; - if(_dynamic_scaling_enabled && _scaling_config.min_threads > min_allowed) - min_allowed = _scaling_config.min_threads; - if(_threads.size() <= min_allowed) - { - // Restore the claim — a future set_threads or grow will - // either cancel it or the pool will be large enough. - _remove_count.fetch_add(1,std::memory_order_relaxed); - return false; - } - } + std::size_t min_allowed = 1; + if(_dynamic_scaling_enabled && _scaling_config.min_threads > min_allowed) + min_allowed = _scaling_config.min_threads; + if(_threads.size() <= min_allowed) + { + // Restore the claim — a future set_threads or grow will + // either cancel it or the pool will be large enough. + _remove_count.fetch_add(1,std::memory_order_relaxed); + return false; + } auto it = std::find(_threads.begin(),_threads.end(),t_); if(it == _threads.end())