aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHubert Bugaj <[email protected]>2017-10-10 00:19:08 +0200
committerHubert Bugaj <[email protected]>2017-10-10 00:19:08 +0200
commit2e24a69581709366084d40348232cca1a5758438 (patch)
treebaeabd5401d80ce9a7c9f7f2498c5685de283e46
parentb7754a7e7da855969e9360ca27d0a4939dd61014 (diff)
#1220 - fixed fixes of integer overflow
-rw-r--r--src/lib/utils/barrier.cpp2
-rw-r--r--src/lib/utils/semaphore.cpp8
2 files changed, 3 insertions, 7 deletions
diff --git a/src/lib/utils/barrier.cpp b/src/lib/utils/barrier.cpp
index b8b87d889..ed3878d18 100644
--- a/src/lib/utils/barrier.cpp
+++ b/src/lib/utils/barrier.cpp
@@ -21,7 +21,7 @@ void Barrier::sync()
{
std::unique_lock<mutex_type> lock(m_mutex);
- if(m_value >= 1)
+ if(m_value > 1)
{
--m_value;
const size_t current_syncs = m_syncs;
diff --git a/src/lib/utils/semaphore.cpp b/src/lib/utils/semaphore.cpp
index a442148f8..e990ded41 100644
--- a/src/lib/utils/semaphore.cpp
+++ b/src/lib/utils/semaphore.cpp
@@ -19,26 +19,22 @@ void Semaphore::release(size_t n)
{
lock_guard_type<mutex_type> lock(m_mutex);
- 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)
+ if(m_value-- <= 0)
{
m_cond.wait(lock, [this] { return m_wakeups > 0; });
--m_wakeups;
}
-
- --m_value;
}
}