From 462020d19a7f6504695255b5a33f2df04e50daec Mon Sep 17 00:00:00 2001 From: "Antonio S. Musumeci" Date: Fri, 10 Apr 2026 13:44:27 -0400 Subject: [PATCH] Make _scaling_config const to enforce write-once invariant _scaling_config was documented as read-only after construction but nothing prevented accidental mutation. Move its initialization from the constructor body into the member initializer list (using a ternary to handle the nullptr case) and mark it const. _autoscale_enabled cannot be made const because the constructor clears it if the monitor thread fails to spawn. Co-Authored-By: Claude Opus 4.6 (1M context) --- vendored/libfuse/include/thread_pool.hpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/vendored/libfuse/include/thread_pool.hpp b/vendored/libfuse/include/thread_pool.hpp index cbd77fb3..5b331861 100644 --- a/vendored/libfuse/include/thread_pool.hpp +++ b/vendored/libfuse/include/thread_pool.hpp @@ -173,11 +173,11 @@ private: std::atomic _tasks_completed{0}; // Auto-scaling state - // _autoscale_enabled and _scaling_config are set once in the - // constructor before any threads start and are thereafter read-only. - // No synchronization is needed for their accesses. - bool _autoscale_enabled; - ScalingConfig _scaling_config; + // _autoscale_enabled is set in the constructor and may be cleared + // if the monitor thread fails to spawn. Read-only after ctor. + // _scaling_config is fully immutable after construction. + bool _autoscale_enabled; + ScalingConfig const _scaling_config; pthread_t _monitor_thread; pthread_mutex_t _monitor_mutex; pthread_cond_t _monitor_cond; @@ -204,7 +204,7 @@ ThreadPool::ThreadPool(const unsigned thread_count_, : _queue(max_queue_depth_), _name(name_), _autoscale_enabled(scaling_config_ != nullptr), - _scaling_config(), + _scaling_config(scaling_config_ ? *scaling_config_ : ScalingConfig{}), _monitor_thread(), _monitor_mutex(PTHREAD_MUTEX_INITIALIZER), _monitor_cond() @@ -219,9 +219,6 @@ ThreadPool::ThreadPool(const unsigned thread_count_, pthread_condattr_destroy(&attr); } - if(scaling_config_) - _scaling_config = *scaling_config_; - // Clamp initial thread count to ScalingConfig bounds when auto-scaling. std::size_t count = thread_count_; if(_autoscale_enabled)