Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#6093: Circumvent a problem during reloadDecls. When assigning the ne…
…w syntax block to an existing declaration, the changed signal might trigger a new call to the DeclarationManager API, which waits for the parser tasks to finish. The finish tasks must not employ any locks, otherwise it will deadlock.
  • Loading branch information
codereader committed Sep 11, 2022
1 parent 75b01ac commit e885308
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions radiantcore/decl/DeclarationManager.cpp
Expand Up @@ -256,28 +256,26 @@ void DeclarationManager::waitForTypedParsersToFinish()
// Acquire the lock to modify the cleanup tasks list
auto declLock = std::make_unique<std::lock_guard<std::recursive_mutex>>(_declarationAndCreatorLock);

// Add the task to the list, we need to wait for it when
// shutting down the module
auto& task = _parserCleanupTasks.emplace_back(
std::async(std::launch::async, [this]()
{
// Extract all parsers while we hold the lock
std::vector<std::unique_ptr<DeclarationFolderParser>> parsersToFinish;
// Extract all parsers while we hold the lock
std::vector<std::unique_ptr<DeclarationFolderParser>> parsersToFinish;

{
std::lock_guard declLock(_declarationAndCreatorLock);
for (auto& [_, decl] : _declarationsByType)
{
if (decl.parser)
{
parsersToFinish.emplace_back(std::move(decl.parser));
}
}

for (auto& [_, decl] : _declarationsByType)
{
if (decl.parser)
{
parsersToFinish.emplace_back(std::move(decl.parser));
}
}
}
if (parsersToFinish.empty()) return; // nothing to do

// With the lock released, let all parsers finish their work
parsersToFinish.clear();
// Add the task to the list, we need to wait for it when shutting down the module
// Move the collected parsers to the lambda
auto& task = _parserCleanupTasks.emplace_back(
std::async(std::launch::async, [parsers = std::move(parsersToFinish)]() mutable
{
// Without locking anything, just let all parsers finish their work
parsers.clear();
})
);

Expand Down

0 comments on commit e885308

Please sign in to comment.