From 0bfa0bcd79f787db6194270bb838ae04ca46587e Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 3 Jul 2025 17:03:39 +1000 Subject: [ORC] Replace ThreadSafeContext::getContext with withContextDo. (#146819) This removes ThreadSafeContext::Lock, ThreadSafeContext::getLock, and ThreadSafeContext::getContext, and replaces them with a ThreadSafeContext::withContextDo method (and const override). The new method can be used to access an existing ThreadSafeContext-wrapped LLVMContext in a safe way: ThreadSafeContext TSCtx = ... ; TSCtx.withContextDo([](LLVMContext *Ctx) { // this closure has exclusive access to Ctx. }); The new API enforces correct locking, whereas the old APIs relied on manual locking (which almost no in-tree code preformed, relying instead on incidental exclusive access to the ThreadSafeContext). --- llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp') diff --git a/llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp b/llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp index 2e128dd23744..c927f2149469 100644 --- a/llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ThreadSafeModule.cpp @@ -53,9 +53,11 @@ ThreadSafeModule cloneToNewContext(const ThreadSafeModule &TSM, "cloned module buffer"); ThreadSafeContext NewTSCtx(std::make_unique()); - auto ClonedModule = cantFail( - parseBitcodeFile(ClonedModuleBufferRef, *NewTSCtx.getContext())); - ClonedModule->setModuleIdentifier(M.getName()); + auto ClonedModule = NewTSCtx.withContextDo([&](LLVMContext *Ctx) { + auto TmpM = cantFail(parseBitcodeFile(ClonedModuleBufferRef, *Ctx)); + TmpM->setModuleIdentifier(M.getName()); + return TmpM; + }); return ThreadSafeModule(std::move(ClonedModule), std::move(NewTSCtx)); }); } -- cgit v1.2.3