diff --git a/core/metacling/src/TClingClassInfo.cxx b/core/metacling/src/TClingClassInfo.cxx index a6275d495cf6d96ee2827d40ed0e4e632cfe631a..726c2788e9ad33d2c4766482dbbcf80315054cac 100644 --- a/core/metacling/src/TClingClassInfo.cxx +++ b/core/metacling/src/TClingClassInfo.cxx @@ -135,6 +135,7 @@ void TClingClassInfo::AddBaseOffsetValue(const clang::Decl* decl, ptrdiff_t offs // determined by the parameter decl. OffsetPtrFunc_t executableFunc = 0; + std::unique_lock<std::mutex> lock(fOffsetCacheMutex); fOffsetCache[decl] = std::make_pair(offset, executableFunc); } @@ -611,7 +612,7 @@ ptrdiff_t TClingClassInfo::GetBaseOffset(TClingClassInfo* base, void* address, b { { - R__READ_LOCKGUARD(ROOT::gCoreMutex); + std::unique_lock<std::mutex> lock(fOffsetCacheMutex); // Check for the offset in the cache. auto iter = fOffsetCache.find(base->GetDecl()); diff --git a/core/metacling/src/TClingClassInfo.h b/core/metacling/src/TClingClassInfo.h index 32d395b3d14840e03586d933d4b0500da56ac259..f89388301a27f28632cd6be5ca6056d70eebef26 100644 --- a/core/metacling/src/TClingClassInfo.h +++ b/core/metacling/src/TClingClassInfo.h @@ -34,6 +34,7 @@ #include <vector> #include <string> #include <utility> +#include <mutex> #include "llvm/ADT/DenseMap.h" @@ -69,6 +70,8 @@ private: std::vector<clang::DeclContext::decl_iterator> fIterStack; // Recursion stack for traversing nested scopes. std::string fTitle; // The meta info for the class. std::string fDeclFileName; // Name of the file where the underlying entity is declared. + + std::mutex fOffsetCacheMutex; llvm::DenseMap<const clang::Decl*, std::pair<ptrdiff_t, OffsetPtrFunc_t> > fOffsetCache; // Functions already generated for offsets. explicit TClingClassInfo() = delete; @@ -82,11 +85,21 @@ public: // Types public: + TClingClassInfo(const TClingClassInfo &rhs) : // Copy all but the mutex + TClingDeclInfo(rhs), + fInterp(rhs.fInterp), fFirstTime(rhs.fFirstTime), fDescend(rhs.fDescend), + fIterAll(rhs.fIterAll), fIsIter(rhs.fIsIter), fIter(rhs.fIter), + fType(rhs.fType), fIterStack(rhs.fIterStack), fTitle(rhs.fTitle), + fDeclFileName(rhs.fDeclFileName), fOffsetCache(rhs.fOffsetCache) + {} explicit TClingClassInfo(cling::Interpreter *, Bool_t all = kTRUE); explicit TClingClassInfo(cling::Interpreter *, const char *classname, bool intantiateTemplate = kTRUE); explicit TClingClassInfo(cling::Interpreter *, const clang::Type &); explicit TClingClassInfo(cling::Interpreter *, const clang::Decl *); - void AddBaseOffsetFunction(const clang::Decl* decl, OffsetPtrFunc_t func) { fOffsetCache[decl] = std::make_pair(0L, func); } + void AddBaseOffsetFunction(const clang::Decl* decl, OffsetPtrFunc_t func) { + std::unique_lock<std::mutex> lock(fOffsetCacheMutex); + fOffsetCache[decl] = std::make_pair(0L, func); + } void AddBaseOffsetValue(const clang::Decl* decl, ptrdiff_t offset); long ClassProperty() const; void Delete(void *arena, const ROOT::TMetaUtils::TNormalizedCtxt &normCtxt) const;