aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Interpreter/Interpreter.cpp
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2025-07-03 17:03:39 +1000
committerGitHub <noreply@github.com>2025-07-03 17:03:39 +1000
commit0bfa0bcd79f787db6194270bb838ae04ca46587e (patch)
tree29d354c52338894199e02f5a1b9c660ad55f0a99 /clang/lib/Interpreter/Interpreter.cpp
parent9234d077522ea3718e9486a28df49e7cfb4c336a (diff)
downloadllvm-0bfa0bcd79f787db6194270bb838ae04ca46587e.zip
llvm-0bfa0bcd79f787db6194270bb838ae04ca46587e.tar.gz
llvm-0bfa0bcd79f787db6194270bb838ae04ca46587e.tar.bz2
[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).
Diffstat (limited to 'clang/lib/Interpreter/Interpreter.cpp')
-rw-r--r--clang/lib/Interpreter/Interpreter.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 2f11065..98fc0a5 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -373,8 +373,11 @@ Interpreter::Interpreter(std::unique_ptr<CompilerInstance> Instance,
auto LLVMCtx = std::make_unique<llvm::LLVMContext>();
TSCtx = std::make_unique<llvm::orc::ThreadSafeContext>(std::move(LLVMCtx));
- Act = std::make_unique<IncrementalAction>(*CI, *TSCtx->getContext(), ErrOut,
- *this, std::move(Consumer));
+ Act = TSCtx->withContextDo([&](llvm::LLVMContext *Ctx) {
+ return std::make_unique<IncrementalAction>(*CI, *Ctx, ErrOut, *this,
+ std::move(Consumer));
+ });
+
if (ErrOut)
return;
CI->ExecuteAction(*Act);
@@ -495,10 +498,10 @@ Interpreter::createWithCUDA(std::unique_ptr<CompilerInstance> CI,
std::unique_ptr<Interpreter> Interp = std::move(*InterpOrErr);
llvm::Error Err = llvm::Error::success();
- llvm::LLVMContext &LLVMCtx = *Interp->TSCtx->getContext();
- auto DeviceAct =
- std::make_unique<IncrementalAction>(*DCI, LLVMCtx, Err, *Interp);
+ auto DeviceAct = Interp->TSCtx->withContextDo([&](llvm::LLVMContext *Ctx) {
+ return std::make_unique<IncrementalAction>(*DCI, *Ctx, Err, *Interp);
+ });
if (Err)
return std::move(Err);