Skip to content

Commit 48a92fa

Browse files
committed
[NFC][lldb] Replace ThreadSafeReflectionContext with LockGuarded
1 parent 50533b0 commit 48a92fa

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/ReflectionContextInterface.h

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "llvm/ADT/SmallVector.h"
2525
#include "llvm/ADT/StringRef.h"
2626
#include "llvm/Support/Memory.h"
27+
#include "LockGuarded.h"
2728

2829
namespace swift {
2930
namespace Demangle {
@@ -146,31 +147,6 @@ class ReflectionContextInterface {
146147
StripSignedPointer(swift::remote::RemoteAbsolutePointer pointer) = 0;
147148
};
148149

149-
/// A wrapper around TargetReflectionContext, which holds a lock to ensure
150-
/// exclusive access.
151-
struct ThreadSafeReflectionContext {
152-
ThreadSafeReflectionContext(ReflectionContextInterface *reflection_ctx,
153-
std::recursive_mutex &mutex)
154-
: m_reflection_ctx(reflection_ctx), m_lock(mutex, std::adopt_lock) {}
155-
156-
static ThreadSafeReflectionContext MakeInvalid() {
157-
// This exists so we can create an "empty" reflection context in the stub
158-
// language runtime.
159-
static std::recursive_mutex mutex;
160-
return ThreadSafeReflectionContext(nullptr, mutex);
161-
}
162-
163-
ReflectionContextInterface *operator->() const { return m_reflection_ctx; }
164-
165-
operator bool() const { return m_reflection_ctx != nullptr; }
166-
167-
private:
168-
ReflectionContextInterface *m_reflection_ctx;
169-
// This lock operates on a recursive mutex because the initialization
170-
// of ReflectionContext recursive calls itself (see
171-
// SwiftLanguageRuntimeImpl::SetupReflection).
172-
std::lock_guard<std::recursive_mutex> m_lock;
173-
};
174-
150+
using ThreadSafeReflectionContext = LockGuarded<ReflectionContextInterface>;
175151
} // namespace lldb_private
176152
#endif

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class SwiftLanguageRuntimeStub {
235235

236236
ThreadSafeReflectionContext GetReflectionContext() {
237237
STUB_LOG();
238-
return ThreadSafeReflectionContext::MakeInvalid();
238+
return ThreadSafeReflectionContext();
239239
}
240240

241241
bool GetDynamicTypeAndAddress(ValueObject &in_value,

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ class TypeBase;
5151
} // namespace swift
5252

5353
namespace lldb_private {
54-
struct ThreadSafeReflectionContext;
54+
template <typename T>
55+
struct LockGuarded;
5556

5657
class SwiftLanguageRuntimeStub;
5758
class SwiftLanguageRuntimeImpl;
5859
class ReflectionContextInterface;
5960

61+
using ThreadSafeReflectionContext = LockGuarded<ReflectionContextInterface>;
62+
6063
class SwiftLanguageRuntime : public LanguageRuntime {
6164
protected:
6265
SwiftLanguageRuntime(Process *process);

0 commit comments

Comments
 (0)