From b7754a7e7da855969e9360ca27d0a4939dd61014 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Mon, 9 Oct 2017 19:51:20 +0200 Subject: #1220 - fixed signed overflow warnings --- src/lib/utils/barrier.cpp | 5 +++-- src/lib/utils/semaphore.cpp | 17 +++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/lib/utils/barrier.cpp b/src/lib/utils/barrier.cpp index 3c721d905..b8b87d889 100644 --- a/src/lib/utils/barrier.cpp +++ b/src/lib/utils/barrier.cpp @@ -20,9 +20,10 @@ void Barrier::wait(size_t delta) void Barrier::sync() { std::unique_lock lock(m_mutex); - --m_value; - if(m_value > 0) + + if(m_value >= 1) { + --m_value; const size_t current_syncs = m_syncs; m_cond.wait(lock, [this, ¤t_syncs] { return m_syncs != current_syncs; }); } diff --git a/src/lib/utils/semaphore.cpp b/src/lib/utils/semaphore.cpp index 62c31d3e3..a442148f8 100644 --- a/src/lib/utils/semaphore.cpp +++ b/src/lib/utils/semaphore.cpp @@ -19,25 +19,26 @@ void Semaphore::release(size_t n) { lock_guard_type lock(m_mutex); - ++m_value; - - if(m_value <= 0) + if(m_value < 0) { ++m_wakeups; m_cond.notify_one(); } + + ++m_value; } } void Semaphore::acquire() { std::unique_lock lock(m_mutex); + if(m_value <= 0) + { + m_cond.wait(lock, [this] { return m_wakeups > 0; }); + --m_wakeups; + } + --m_value; - if(m_value < 0) - { - m_cond.wait(lock, [this] { return m_wakeups > 0; }); - --m_wakeups; - } } } -- cgit v1.2.3