// DragonX Wallet - ImGui Edition // Copyright 2024-2026 The Hush Developers // Released under the GPLv3 #pragma once // Coalesces mining thread-count picks. The Mining tab reports every intermediate value of a gesture (a tile // drag crosses up to ~24 tiles; the -/+ stepper is clicked repeatedly); only the LAST one should reach the // settings file and the miner, once, when the input settles: on drag release, or kDebounceSec after the // last click. Pure: time is passed in; nothing here touches settings, the miner or ImGui. namespace dragonx { namespace services { class MiningThreadCommit { public: static constexpr double kDebounceSec = 0.5; // The user picked `threads` at `now` (seconds, any monotonic clock). Latest wins. void select(int threads, double now) { target_ = threads; pending_ = true; due_ = now + kDebounceSec; } // The drag that produced the pending pick ended: it is due now, not after the debounce. void release(double now) { if (pending_ && due_ > now) due_ = now; } void cancel() { pending_ = false; } bool pending() const { return pending_; } // Once per frame. `held`: a drag is still in progress (nothing commits until it ends). Returns true // exactly once per settled pick and sets `out` to it. bool take(double now, bool held, int& out) { if (!pending_ || held || now < due_) return false; pending_ = false; out = target_; return true; } private: int target_ = 0; bool pending_ = false; double due_ = 0.0; }; // The pool thread count a wanted count is compared with: the newest start/retarget posted (it includes a // restart still queued on the mining-control thread), else the count the running xmrig was started with, // else what its HTTP API last reported (that lags a restart by seconds, so it is only a last resort). inline int effectivePoolThreads(int queuedTarget, int requested, int apiActive) { if (queuedTarget > 0) return queuedTarget; if (requested > 0) return requested; return apiActive; } } // namespace services } // namespace dragonx