Commit ec8d2a29 authored by Aleksy Barcz's avatar Aleksy Barcz

deadlock in UDIC/UDIM fix continuation

+ follow-up of "fixed deadlock in defined initialization"
+ previous fix fixed the deadlock in one case, but not in the general case, as unfortunately there are other call-traces that lead to the deadlock
+ this fixes a sequence, where thread 1 calls UDIM::AddUserDef (acquires mutex), which calls UDIC::AddUserDef (acquires m_lock); while thread 2 calls PCIC::GetConfig (acquires m_lock), which calls UDIC::AddConfig, which calls UDIM::PopConfig (acquires mutex)
+ the general design flaw is that UDIM can call UDIC and vice versa. This is wrong and especially bug-prone when using locks.
+ this fix should fix the general case. The design flaw remains to be fixed, but now whenever UDIM calls UDIC, it does so without holding mutex (fixed both places in code where I found such a situation). So both locks are held only on the path from UDIC to UDIM and not vice versa.
parent e471e6f7
......@@ -58,15 +58,15 @@ TSzarpConfig* UserDefinedIPKManager::PopConfig(const std::wstring &prefix) {
}
void UserDefinedIPKManager::AddUserDefined(const std::wstring& prefix, TParam *param) {
boost::unique_lock<boost::shared_mutex> lock(mutex);
if (ipk->AddUserDefined(prefix, param)) {
boost::unique_lock<boost::shared_mutex> lock(mutex);
m_extra_params[prefix].emplace_back(param);
}
}
void UserDefinedIPKManager::RemoveUserDefined(const std::wstring& prefix, TParam *param) {
boost::unique_lock<boost::shared_mutex> lock(mutex);
if (ipk->RemoveUserDefined(prefix, param)) {
boost::unique_lock<boost::shared_mutex> lock(mutex);
auto& tp = m_extra_params[prefix];
auto ei = std::find_if(tp.begin(), tp.end(),
[param] (std::shared_ptr<TParam> &_p) { return _p.get() == param; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment