Skip to content

Commit f5d4c14

Browse files
committed
[lldb] Defer taking Swift scatch context lock
1 parent 464b04e commit f5d4c14

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lldb/source/Target/Target.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,6 +2747,15 @@ llvm::Optional<SwiftScratchContextReader> Target::GetSwiftScratchContext(
27472747
log->Printf("not allowed to create a new context\n");
27482748
return nullptr;
27492749
}
2750+
2751+
// Call for its side effects of establishing the Swift scratch type system.
2752+
auto type_system_or_err =
2753+
GetScratchTypeSystemForLanguage(eLanguageTypeSwift, false);
2754+
if (!type_system_or_err) {
2755+
llvm::consumeError(type_system_or_err.takeError());
2756+
return nullptr;
2757+
}
2758+
27502759
if (!GetSwiftScratchContextLock().try_lock()) {
27512760
if (log)
27522761
log->Printf("couldn't acquire scratch context lock\n");
@@ -2756,8 +2765,12 @@ llvm::Optional<SwiftScratchContextReader> Target::GetSwiftScratchContext(
27562765
auto unlock = llvm::make_scope_exit(
27572766
[this] { GetSwiftScratchContextLock().unlock(); });
27582767

2759-
auto type_system_or_err =
2760-
GetScratchTypeSystemForLanguage(eLanguageTypeSwift, false);
2768+
// With the lock held, get the current scratch type system. This ensures the
2769+
// current instance is used even in the unlikely event it was changed during
2770+
// the brief window between the call to `GetScratchTypeSystemForLanguage`
2771+
// and taking the lock.
2772+
type_system_or_err = m_scratch_type_system_map.GetTypeSystemForLanguage(
2773+
eLanguageTypeSwift, this, false);
27612774
if (!type_system_or_err) {
27622775
llvm::consumeError(type_system_or_err.takeError());
27632776
return nullptr;

0 commit comments

Comments
 (0)