Commit 068611f0 by Nicolas Capens Committed by Nicolas Capens

Fix JIT on separate thread

When JIT_IN_SEPARATE_THREAD is defined we generate Reactor routines on LLVM in a new thread. Since concurrent code generation was enabled by making ::jit thread-local, we need to assign it the pointer of the thread that creates the new thread. Bug: b/153803432 Change-Id: Ia7454ac5823d61a1fb139b337d2af2de3a5104af Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/44048Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com>
parent 377573cc
...@@ -634,7 +634,11 @@ std::shared_ptr<Routine> Nucleus::acquireRoutine(const char *name, const Config: ...@@ -634,7 +634,11 @@ std::shared_ptr<Routine> Nucleus::acquireRoutine(const char *name, const Config:
{ {
std::shared_ptr<Routine> routine; std::shared_ptr<Routine> routine;
auto acquire = [&]() { auto acquire = [&](std::unique_ptr<rr::JITBuilder> jitBuilder) {
// ::jit is thread-local, so when this is executed on a separate thread (see JIT_IN_SEPARATE_THREAD)
// it needs to be assigned the value from the parent thread.
jit = std::move(jitBuilder);
auto cfg = cfgEdit.apply(jit->config); auto cfg = cfgEdit.apply(jit->config);
if(jit->builder->GetInsertBlock()->empty() || !jit->builder->GetInsertBlock()->back().isTerminator()) if(jit->builder->GetInsertBlock()->empty() || !jit->builder->GetInsertBlock()->back().isTerminator())
...@@ -691,10 +695,10 @@ std::shared_ptr<Routine> Nucleus::acquireRoutine(const char *name, const Config: ...@@ -691,10 +695,10 @@ std::shared_ptr<Routine> Nucleus::acquireRoutine(const char *name, const Config:
// FIXME(b/149829034): This is not a long-term solution. Reactor has no control // FIXME(b/149829034): This is not a long-term solution. Reactor has no control
// over the threading and stack sizes of its users, so this should be addressed // over the threading and stack sizes of its users, so this should be addressed
// at a higher level instead. // at a higher level instead.
std::thread thread(acquire); std::thread thread(acquire, std::move(jit));
thread.join(); thread.join();
#else #else
acquire(); acquire(std::move(jit));
#endif #endif
return routine; return routine;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment