From cb6d9d4d80079a76c7821836c73ade0a675cad99 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 25 Aug 2025 15:04:17 +0200 Subject: [PATCH] Make IoEngine#m_CpuBoundSemaphore unsigned --- lib/base/io-engine.cpp | 6 +++--- lib/base/io-engine.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/base/io-engine.cpp b/lib/base/io-engine.cpp index ce531923a..0c0be835e 100644 --- a/lib/base/io-engine.cpp +++ b/lib/base/io-engine.cpp @@ -77,10 +77,10 @@ bool CpuBoundWork::TryAcquireSlot() auto& ie (IoEngine::Get()); auto freeSlots (ie.m_CpuBoundSemaphore.load()); - while (freeSlots > 0) { + while (freeSlots > 0u) { // If ie.m_CpuBoundSemaphore was changed after the last load, // compare_exchange_weak() will load its latest value into freeSlots for us to retry until... - if (ie.m_CpuBoundSemaphore.compare_exchange_weak(freeSlots, freeSlots - 1)) { + if (ie.m_CpuBoundSemaphore.compare_exchange_weak(freeSlots, freeSlots - 1u)) { // ... either we successfully decrement ie.m_CpuBoundSemaphore by one, ... return true; } @@ -106,7 +106,7 @@ void CpuBoundWork::Done() // The constructor takes the slow path only if the semaphore is full, // so we only have to wake up constructors if the semaphore was full. // This works because after fetch_add(), TryAcquireSlot() (fast path) will succeed. - if (ie.m_CpuBoundSemaphore.fetch_add(1) == 0) { + if (ie.m_CpuBoundSemaphore.fetch_add(1) == 0u) { // So now there are only slow path subscribers from just before the fetch_add() to be woken up. // Precisely, only subscribers from just before the fetch_add() which turned 0 to 1. diff --git a/lib/base/io-engine.hpp b/lib/base/io-engine.hpp index 23be1a146..b48ae6012 100644 --- a/lib/base/io-engine.hpp +++ b/lib/base/io-engine.hpp @@ -157,7 +157,7 @@ private: std::vector m_Threads; boost::asio::deadline_timer m_AlreadyExpiredTimer; - std::atomic_int_fast32_t m_CpuBoundSemaphore; + std::atomic_uint_fast32_t m_CpuBoundSemaphore; std::mutex m_CpuBoundWaitingMutex; std::vector::Ptr>> m_CpuBoundWaiting; };