From df085dd86d87b3f0bbef4a9a76481a8f6aeb531c Mon Sep 17 00:00:00 2001 From: rachytski Date: Fri, 27 Jan 2012 22:37:04 +0400 Subject: [PATCH] fixed deadlock issue in joinFence function. --- base/fence_manager.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/base/fence_manager.cpp b/base/fence_manager.cpp index 6f2cca66c9..938d959566 100644 --- a/base/fence_manager.cpp +++ b/base/fence_manager.cpp @@ -62,6 +62,8 @@ void FenceManager::signalFence(int id) threads::Condition * cond = it->second; + threads::ConditionGuard fenceGuard(*cond); + /// erasing fence from active fences m_activeFences.erase(it); @@ -69,7 +71,7 @@ void FenceManager::signalFence(int id) m_conditionPool.push_back(cond); /// signalling to all waiting fences - cond->Signal(true); + fenceGuard.Signal(true); } void FenceManager::joinFence(int id) @@ -92,8 +94,9 @@ void FenceManager::joinFence(int id) cond = it->second; } - threads::ConditionGuard g(*cond); - g.Wait(); + threads::ConditionGuard fenceGuard(*cond); + if (m_activeFences.find(id) != m_activeFences.end()) + fenceGuard.Wait(); } void FenceManager::cancel() @@ -102,8 +105,19 @@ void FenceManager::cancel() m_isCancelled = true; - map::iterator it = m_activeFences.begin(); + list > tempList; - for (; it != m_activeFences.end(); ++it) - it->second->Signal(true); + for (map::iterator it = m_activeFences.begin(); + it != m_activeFences.end(); + ++it) + tempList.push_back(make_pair(it->first, it->second)); + + for (list >::const_iterator it = tempList.begin(); + it != tempList.end(); + ++it) + { + threads::ConditionGuard fenceGuard(*it->second); + m_activeFences.erase(it->first); + fenceGuard.Signal(true); + } }