diff --git a/core/metacling/src/TClingClassInfo.cxx b/core/metacling/src/TClingClassInfo.cxx index 96a7aeffb0b7fb3a18a9866f806ace5f05c05607..ac17254a86847565352624a2fde8c4c0a7de12d4 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 b511be99eb9fb32df1c8c2364606566a831d2f4d..f89388301a27f28632cd6be5ca6056d70eebef26 100644 --- a/core/metacling/src/TClingClassInfo.h +++ b/core/metacling/src/TClingClassInfo.h @@ -33,6 +33,9 @@ #include <vector> #include <string> +#include <utility> +#include <mutex> + #include "llvm/ADT/DenseMap.h" namespace cling { @@ -67,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; @@ -80,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;