[clang-tools-extra] r368313 - [clang-doc] Protect Index with mutex during reducing and generation stage

Diego Astiazaran via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 8 10:14:17 PDT 2019


Author: diegoastiazaran
Date: Thu Aug  8 10:14:17 2019
New Revision: 368313

URL: http://llvm.org/viewvc/llvm-project?rev=368313&view=rev
Log:
[clang-doc] Protect Index with mutex during reducing and generation stage

Idx in ClangDocContext instance was being modified by multiple threads
causing a seg fault.
A mutex is added to avoid this.

Differential Revision: https://reviews.llvm.org/D65915

Modified:
    clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp

Modified: clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp?rev=368313&r1=368312&r2=368313&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp Thu Aug  8 10:14:17 2019
@@ -36,6 +36,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Signals.h"
@@ -246,6 +247,7 @@ int main(int argc, const char **argv) {
   llvm::outs() << "Reducing " << USRToBitcode.size() << " infos...\n";
   std::atomic<bool> Error;
   Error = false;
+  llvm::sys::Mutex IndexMutex;
   // ExecutorConcurrency is a flag exposed by AllTUsExecution.h
   llvm::ThreadPool Pool(ExecutorConcurrency == 0 ? llvm::hardware_concurrency()
                                                  : ExecutorConcurrency);
@@ -289,8 +291,10 @@ int main(int argc, const char **argv) {
         return;
       }
 
+      IndexMutex.lock();
       // Add a reference to this Info in the Index
       clang::doc::Generator::addInfoToIndex(CDCtx.Idx, I);
+      IndexMutex.unlock();
 
       if (auto Err = G->get()->generateDocForInfo(I, InfoOS, CDCtx))
         llvm::errs() << toString(std::move(Err)) << "\n";




More information about the cfe-commits mailing list