Skip to content

[lldb] fix dead lock in TypeCategoryMap.cpp #87540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions lldb/source/DataFormatters/TypeCategoryMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,31 @@ TypeCategoryMap::TypeCategoryMap(IFormatChangeListener *lst)
}

void TypeCategoryMap::Add(KeyType name, const TypeCategoryImplSP &entry) {
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
m_map[name] = entry;
{
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
m_map[name] = entry;
}
// Release the mutex to avoid a potential deadlock between
// TypeCategoryMap::m_map_mutex and
// FormatManager::m_language_categories_mutex which can be acquired in
// reverse order when calling FormatManager::Changed.
if (listener)
listener->Changed();
}

bool TypeCategoryMap::Delete(KeyType name) {
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
MapIterator iter = m_map.find(name);
if (iter == m_map.end())
return false;
m_map.erase(name);
Disable(name);
{
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
MapIterator iter = m_map.find(name);
if (iter == m_map.end())
return false;
m_map.erase(name);
Disable(name);
}
// Release the mutex to avoid a potential deadlock between
// TypeCategoryMap::m_map_mutex and
// FormatManager::m_language_categories_mutex which can be acquired in
// reverse order when calling FormatManager::Changed.
if (listener)
listener->Changed();
return true;
Expand Down Expand Up @@ -123,9 +135,15 @@ void TypeCategoryMap::DisableAllCategories() {
}

void TypeCategoryMap::Clear() {
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
m_map.clear();
m_active_categories.clear();
{
std::lock_guard<std::recursive_mutex> guard(m_map_mutex);
m_map.clear();
m_active_categories.clear();
}
// Release the mutex to avoid a potential deadlock between
// TypeCategoryMap::m_map_mutex and
// FormatManager::m_language_categories_mutex which can be acquired in
// reverse order when calling FormatManager::Changed.
if (listener)
listener->Changed();
}
Expand Down