diff options
author | Hubert Bugaj <[email protected]> | 2017-10-09 19:51:20 +0200 |
---|---|---|
committer | Hubert Bugaj <[email protected]> | 2017-10-09 19:51:20 +0200 |
commit | b7754a7e7da855969e9360ca27d0a4939dd61014 (patch) | |
tree | 01bc0321b870b06d91b00a8fc2ae8cfe29046fa7 /src/lib/utils | |
parent | 2f39b15e4b7a0fd5da87d5142c5a94c129cae09d (diff) |
#1220 - fixed signed overflow warnings
Diffstat (limited to 'src/lib/utils')
-rw-r--r-- | src/lib/utils/barrier.cpp | 5 | ||||
-rw-r--r-- | src/lib/utils/semaphore.cpp | 17 |
2 files changed, 12 insertions, 10 deletions
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<mutex_type> 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<mutex_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<mutex_type> 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; - } } } |