mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
_remove_thread_scaling_locked previously enqueued a heap-allocated lambda (capturing a shared_ptr<promise>) to signal a specific worker to exit. This had two problems: 1. Bug: if the 5-second future::wait_for timed out, the function returned -EBUSY but the lambda remained in the queue. When a worker eventually executed it, it would unconditionally set _tl_should_exit and call _remove_self, silently killing an arbitrary thread with no compensating add. 2. Held _scaling_mutex for up to 5 seconds while blocking on the future, serializing all concurrent scaling operations (add_thread, remove_thread, _maybe_grow_on_pressure, monitor hill-climb). Replace the entire mechanism with an atomic _remove_count counter. _remove_thread_scaling_locked simply increments the counter and returns immediately. After each task, _process_func does a CAS-decrement; the winning worker detaches itself via _remove_self and exits. This eliminates: - All heap allocations (shared_ptr, promise, lambda captures) - The thread-local _tl_should_exit flag - The 5-second blocking window under _scaling_mutex - The stale-lambda bug entirely (no lambda to go stale) - The <memory> include (no longer needed) During shutdown, _remove_self is a no-op (_stop is set), so a worker that wins the CAS stays in _threads and is joined normally by the destructor. Any outstanding _remove_count credits are harmlessly abandoned. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| moodycamel | ||
| base_types.h | ||
| bounded_queue.hpp | ||
| debug.hpp | ||
| extern_c.h | ||
| fatal.hpp | ||
| fs_dirent64.hpp | ||
| fuse.h | ||
| fuse_attr.h | ||
| fuse_cfg.hpp | ||
| fuse_common.h | ||
| fuse_conn_info.hpp | ||
| fuse_dirent.h | ||
| fuse_direntplus.h | ||
| fuse_dirents.hpp | ||
| fuse_entry.h | ||
| fuse_kernel.h | ||
| fuse_lowlevel.h | ||
| fuse_msgbuf.hpp | ||
| fuse_msgbuf_t.h | ||
| fuse_opt.h | ||
| fuse_pollhandle.h | ||
| fuse_req.hpp | ||
| fuse_req_ctx.h | ||
| fuse_timeouts.h | ||
| invocable.h | ||
| kvec.h | ||
| maintenance_thread.hpp | ||
| mutex.hpp | ||
| mutex_debug.hpp | ||
| mutex_ndebug.hpp | ||
| objpool.hpp | ||
| stat_utils.h | ||
| syslog.hpp | ||
| thread_pool.hpp | ||