diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Core.h b/llvm/include/llvm/ExecutionEngine/Orc/Core.h index cb3de04b8469b..b6d1bf08988e2 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/Core.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Core.h @@ -70,6 +70,10 @@ class ResourceTracker : public ThreadSafeRefCountedBase { ~static_cast(1)); } + /// Runs the given callback under the session lock, passing in the associated + /// ResourceKey. This is the safe way to associate resources with trackers. + template Error withResourceKeyDo(Func &&F); + /// Remove all resources associated with this key. Error remove(); @@ -530,8 +534,11 @@ class MaterializationResponsibility { /// emitted or notified of an error. ~MaterializationResponsibility(); - /// Returns the ResourceTracker for this instance. - template Error withResourceKeyDo(Func &&F) const; + /// Runs the given callback under the session lock, passing in the associated + /// ResourceKey. This is the safe way to associate resources with trackers. + template Error withResourceKeyDo(Func &&F) const { + return RT->withResourceKeyDo(std::forward(F)); + } /// Returns the target JITDylib that these symbols are being materialized /// into. @@ -1770,21 +1777,20 @@ class ExecutionSession { JITDispatchHandlers; }; +template Error ResourceTracker::withResourceKeyDo(Func &&F) { + return getJITDylib().getExecutionSession().runSessionLocked([&]() -> Error { + if (isDefunct()) + return make_error(this); + F(getKeyUnsafe()); + return Error::success(); + }); +} + inline ExecutionSession & MaterializationResponsibility::getExecutionSession() const { return JD.getExecutionSession(); } -template -Error MaterializationResponsibility::withResourceKeyDo(Func &&F) const { - return JD.getExecutionSession().runSessionLocked([&]() -> Error { - if (RT->isDefunct()) - return make_error(RT); - F(RT->getKeyUnsafe()); - return Error::success(); - }); -} - template GeneratorT &JITDylib::addGenerator(std::unique_ptr DefGenerator) { auto &G = *DefGenerator;