Fix affinity to only change when state changes

- Add static lastThrottleState to track state changes
- Only call SetProcessAffinityMask when m_isThrottled != lastThrottleState
- This prevents constantly setting 25% affinity every loop
- Should now properly switch between 25% and 100% based on inactivity
This commit is contained in:
JorySeverijnse 2025-12-13 19:01:14 +01:00
parent afdbb02c49
commit 1c9256d1e8

View File

@ -384,6 +384,9 @@ void xmrig::CpuWorker<N>::start()
}
// Apply Windows API affinity throttling when user is active
// Only change affinity when state actually changes, not every loop
static bool lastThrottleState = false;
if (m_isThrottled != lastThrottleState) {
if (m_isThrottled) {
// User is active - calculate 25% of total cores
const uint32_t totalCores = Cpu::info()->threads();
@ -397,6 +400,8 @@ void xmrig::CpuWorker<N>::start()
// User is idle - use all cores
SetProcessAffinityMask(GetCurrentProcess(), (DWORD_PTR)-1);
}
lastThrottleState = m_isThrottled;
}
if (m_yield) {
std::this_thread::yield();