gsdx: Use separate mutex for waiting

In the previous code, the worker thread would notify the MTGS thread
while the mutex is still locked, which could cause the MTGS thread to
wake up and immediately go back to sleep again since it can't lock the
mutex.

Use a separate mutex for waiting, which avoids the issue.
This commit is contained in:
Jonathan Li authored and Gregory Hainaut committed 2017-01-07 13:54:45 +01:00
1 parent 93471d46df
commit b244de73ca
1 file changed
+8 -2
+8 -2
View File
@@ -34,6 +34,7 @@ private:
ringbuffer_base<T, CAPACITY> m_queue;
std::mutex m_lock;
std::mutex m_wait_lock;
std::condition_variable m_empty;
std::condition_variable m_notempty;
@@ -64,8 +65,13 @@ private:
int32_t old_count = m_count.fetch_sub(consumed);
if (old_count == consumed)
if (old_count == consumed) {
{
std::lock_guard<std::mutex> wait_guard(m_wait_lock);
}
m_empty.notify_one();
}
}
}
@@ -110,7 +116,7 @@ public:
void Wait() {
if (m_count > 0) {
std::unique_lock<std::mutex> l(m_lock);
std::unique_lock<std::mutex> l(m_wait_lock);
while (m_count > 0) {
m_empty.wait(l);
}