diff --git a/core/metacling/src/TClingCallFunc.cxx b/core/metacling/src/TClingCallFunc.cxx index a4a8362193b782ac3d3acab52f30020d43705da6..5ecbc7b24a0059fcbbd7ccf082c25b0f915f5a75 100644 --- a/core/metacling/src/TClingCallFunc.cxx +++ b/core/metacling/src/TClingCallFunc.cxx @@ -1675,14 +1675,17 @@ void *TClingCallFunc::InterfaceMethod() const Decl *decl = GetFunctionOrShadowDecl(); R__LOCKGUARD_CLING(gInterpreterMutex); - map<const Decl *, void *>::iterator I = gWrapperStore.find(decl); - if (I != gWrapperStore.end()) { - fWrapper = (tcling_callfunc_Wrapper_t) I->second; - } else { - fWrapper = make_wrapper(); + // check if another thread already did it + if (!fWrapper) { + map<const Decl *, void *>::iterator I = gWrapperStore.find(decl); + if (I != gWrapperStore.end()) { + fWrapper = (tcling_callfunc_Wrapper_t)I->second; + } else { + fWrapper = make_wrapper(); + } } } - return (void *)fWrapper; + return (void *)fWrapper.load(); } bool TClingCallFunc::IsValid() const @@ -1704,11 +1707,14 @@ TInterpreter::CallFuncIFacePtr_t TClingCallFunc::IFacePtr() const Decl *decl = GetFunctionOrShadowDecl(); R__LOCKGUARD_CLING(gInterpreterMutex); - map<const Decl *, void *>::iterator I = gWrapperStore.find(decl); - if (I != gWrapperStore.end()) { - fWrapper = (tcling_callfunc_Wrapper_t) I->second; - } else { - fWrapper = make_wrapper(); + // check if another thread already did it + if (!fWrapper) { + map<const Decl *, void *>::iterator I = gWrapperStore.find(decl); + if (I != gWrapperStore.end()) { + fWrapper = (tcling_callfunc_Wrapper_t)I->second; + } else { + fWrapper = make_wrapper(); + } } } return TInterpreter::CallFuncIFacePtr_t(fWrapper); diff --git a/core/metacling/src/TClingCallFunc.h b/core/metacling/src/TClingCallFunc.h index 876dd1871072c38241dd42946721d7d2f5005276..2026e72853c0d822f2e58ae30cfbc7f487a5903a 100644 --- a/core/metacling/src/TClingCallFunc.h +++ b/core/metacling/src/TClingCallFunc.h @@ -69,7 +69,7 @@ private: /// Number of required arguments size_t fMinRequiredArguments = -1; /// Pointer to compiled wrapper, we do *not* own. - tcling_callfunc_Wrapper_t fWrapper; + std::atomic<tcling_callfunc_Wrapper_t> fWrapper; /// Stored function arguments, we own. mutable llvm::SmallVector<cling::Value, 8> fArgVals; @@ -151,7 +151,7 @@ public: } TClingCallFunc(const TClingCallFunc &rhs) - : fInterp(rhs.fInterp), fWrapper(rhs.fWrapper), fArgVals(rhs.fArgVals) + : fInterp(rhs.fInterp), fWrapper(rhs.fWrapper.load()), fArgVals(rhs.fArgVals) { fMethod = std::unique_ptr<TClingMethodInfo>(new TClingMethodInfo(*rhs.fMethod)); }