aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHubert Bugaj <[email protected]>2017-10-09 19:51:20 +0200
committerHubert Bugaj <[email protected]>2017-10-09 19:51:20 +0200
commitb7754a7e7da855969e9360ca27d0a4939dd61014 (patch)
tree01bc0321b870b06d91b00a8fc2ae8cfe29046fa7 /src
parent2f39b15e4b7a0fd5da87d5142c5a94c129cae09d (diff)
#1220 - fixed signed overflow warnings
Diffstat (limited to 'src')
-rw-r--r--src/lib/utils/barrier.cpp5
-rw-r--r--src/lib/utils/semaphore.cpp17
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, &current_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;
- }
}
}