diff options
Diffstat (limited to 'clang-tools-extra/clangd/GlobalCompilationDatabase.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/GlobalCompilationDatabase.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp index be03e4c2463..3bfc4eca144 100644 --- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp +++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp @@ -152,5 +152,29 @@ void CachingCompilationDb::clear() { Cached.clear(); } +llvm::Optional<tooling::CompileCommand> +InMemoryCompilationDb::getCompileCommand(PathRef File) const { + std::lock_guard<std::mutex> Lock(Mutex); + auto It = Commands.find(File); + if (It == Commands.end()) + return None; + return It->second; +} + +bool InMemoryCompilationDb::setCompilationCommandForFile( + PathRef File, tooling::CompileCommand CompilationCommand) { + std::unique_lock<std::mutex> Lock(Mutex); + auto ItInserted = Commands.insert(std::make_pair(File, CompilationCommand)); + if (ItInserted.second) + return true; + ItInserted.first->setValue(std::move(CompilationCommand)); + return false; +} + +void InMemoryCompilationDb::invalidate(PathRef File) { + std::unique_lock<std::mutex> Lock(Mutex); + Commands.erase(File); +} + } // namespace clangd } // namespace clang |

