Skip to content

Commit

Permalink
#5977: Safely close parser threads when the module is shut down
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jun 19, 2022
1 parent 941062e commit 409ae7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions radiantcore/decl/DeclarationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ void DeclarationManager::initialiseModule(const IApplicationContext& ctx)
rMessage() << getName() << "::initialiseModule called." << std::endl;
}

void DeclarationManager::shutdownModule()
{
auto declLock = std::make_unique<std::lock_guard<std::mutex>>(_declarationLock);
std::vector<std::unique_ptr<DeclarationParser>> parsersToFinish;

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

// Release the lock, destruct all parsers
declLock.reset();
parsersToFinish.clear(); // might block if parsers are running

// All parsers have finished, clear the structure, no need to lock anything
_declarationsByType.clear();
}

module::StaticModuleRegistration<DeclarationManager> _declManagerModule;

}
1 change: 1 addition & 0 deletions radiantcore/decl/DeclarationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class DeclarationManager :
const std::string& getName() const override;
const StringSet& getDependencies() const override;
void initialiseModule(const IApplicationContext& ctx) override;
void shutdownModule() override;

// Invoked once a parser thread has finished. It will move its data over to here.
void onParserFinished(std::map<Type, NamedDeclarations>&& parsedDecls,
Expand Down

0 comments on commit 409ae7a

Please sign in to comment.