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/semaphore.cpp | |
parent | 2f39b15e4b7a0fd5da87d5142c5a94c129cae09d (diff) |
#1220 - fixed signed overflow warnings
Diffstat (limited to 'src/lib/utils/semaphore.cpp')
-rw-r--r-- | src/lib/utils/semaphore.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
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; - } } } |