Skip to content

Commit ea20d27

Browse files
committed
Make the BreakpointLocationCollection mutex recursive
1 parent ffccec4 commit ea20d27

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

lldb/include/lldb/Breakpoint/BreakpointLocationCollection.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class BreakpointLocationCollection {
3232

3333
~BreakpointLocationCollection();
3434

35-
BreakpointLocationCollection &operator=(const BreakpointLocationCollection &rhs);
35+
BreakpointLocationCollection &
36+
operator=(const BreakpointLocationCollection &rhs);
3637

3738
/// Add the breakpoint \a bp_loc_sp to the list.
3839
///
@@ -172,14 +173,14 @@ class BreakpointLocationCollection {
172173
lldb::break_id_t break_loc_id) const;
173174

174175
collection m_break_loc_collection;
175-
mutable std::mutex m_collection_mutex;
176+
mutable std::recursive_mutex m_collection_mutex;
176177
/// These are used if we're preserving breakpoints in this list:
177178
const bool m_preserving_bkpts = false;
178179
std::map<std::pair<lldb::break_id_t, lldb::break_id_t>, lldb::BreakpointSP>
179180
m_preserved_bps;
180181

181182
public:
182-
typedef LockingAdaptedIterable<std::mutex, collection>
183+
typedef LockingAdaptedIterable<std::recursive_mutex, collection>
183184
BreakpointLocationCollectionIterable;
184185
BreakpointLocationCollectionIterable BreakpointLocations() {
185186
return BreakpointLocationCollectionIterable(m_break_loc_collection,

lldb/source/Breakpoint/BreakpointLocationCollection.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ BreakpointLocationCollection::BreakpointLocationCollection(bool preserving)
2424
BreakpointLocationCollection::~BreakpointLocationCollection() = default;
2525

2626
void BreakpointLocationCollection::Add(const BreakpointLocationSP &bp_loc) {
27-
std::lock_guard<std::mutex> guard(m_collection_mutex);
27+
std::lock_guard<std::recursive_mutex> guard(m_collection_mutex);
2828
BreakpointLocationSP old_bp_loc =
2929
FindByIDPair(bp_loc->GetBreakpoint().GetID(), bp_loc->GetID());
3030
if (!old_bp_loc.get()) {
@@ -44,7 +44,7 @@ void BreakpointLocationCollection::Add(const BreakpointLocationSP &bp_loc) {
4444

4545
bool BreakpointLocationCollection::Remove(lldb::break_id_t bp_id,
4646
lldb::break_id_t bp_loc_id) {
47-
std::lock_guard<std::mutex> guard(m_collection_mutex);
47+
std::lock_guard<std::recursive_mutex> guard(m_collection_mutex);
4848
collection::iterator pos = GetIDPairIterator(bp_id, bp_loc_id); // Predicate
4949
if (pos != m_break_loc_collection.end()) {
5050
if (m_preserving_bkpts) {
@@ -117,7 +117,7 @@ const BreakpointLocationSP BreakpointLocationCollection::FindByIDPair(
117117
}
118118

119119
BreakpointLocationSP BreakpointLocationCollection::GetByIndex(size_t i) {
120-
std::lock_guard<std::mutex> guard(m_collection_mutex);
120+
std::lock_guard<std::recursive_mutex> guard(m_collection_mutex);
121121
BreakpointLocationSP stop_sp;
122122
if (i < m_break_loc_collection.size())
123123
stop_sp = m_break_loc_collection[i];
@@ -127,7 +127,7 @@ BreakpointLocationSP BreakpointLocationCollection::GetByIndex(size_t i) {
127127

128128
const BreakpointLocationSP
129129
BreakpointLocationCollection::GetByIndex(size_t i) const {
130-
std::lock_guard<std::mutex> guard(m_collection_mutex);
130+
std::lock_guard<std::recursive_mutex> guard(m_collection_mutex);
131131
BreakpointLocationSP stop_sp;
132132
if (i < m_break_loc_collection.size())
133133
stop_sp = m_break_loc_collection[i];
@@ -168,7 +168,7 @@ bool BreakpointLocationCollection::ShouldStop(
168168
}
169169

170170
bool BreakpointLocationCollection::ValidForThisThread(Thread &thread) {
171-
std::lock_guard<std::mutex> guard(m_collection_mutex);
171+
std::lock_guard<std::recursive_mutex> guard(m_collection_mutex);
172172
collection::iterator pos, begin = m_break_loc_collection.begin(),
173173
end = m_break_loc_collection.end();
174174

@@ -180,7 +180,7 @@ bool BreakpointLocationCollection::ValidForThisThread(Thread &thread) {
180180
}
181181

182182
bool BreakpointLocationCollection::IsInternal() const {
183-
std::lock_guard<std::mutex> guard(m_collection_mutex);
183+
std::lock_guard<std::recursive_mutex> guard(m_collection_mutex);
184184
collection::const_iterator pos, begin = m_break_loc_collection.begin(),
185185
end = m_break_loc_collection.end();
186186

@@ -197,7 +197,7 @@ bool BreakpointLocationCollection::IsInternal() const {
197197

198198
void BreakpointLocationCollection::GetDescription(
199199
Stream *s, lldb::DescriptionLevel level) {
200-
std::lock_guard<std::mutex> guard(m_collection_mutex);
200+
std::lock_guard<std::recursive_mutex> guard(m_collection_mutex);
201201
collection::iterator pos, begin = m_break_loc_collection.begin(),
202202
end = m_break_loc_collection.end();
203203

@@ -212,8 +212,10 @@ BreakpointLocationCollection &BreakpointLocationCollection::operator=(
212212
const BreakpointLocationCollection &rhs) {
213213
if (this != &rhs) {
214214
std::lock(m_collection_mutex, rhs.m_collection_mutex);
215-
std::lock_guard<std::mutex> lhs_guard(m_collection_mutex, std::adopt_lock);
216-
std::lock_guard<std::mutex> rhs_guard(rhs.m_collection_mutex, std::adopt_lock);
215+
std::lock_guard<std::recursive_mutex> lhs_guard(m_collection_mutex,
216+
std::adopt_lock);
217+
std::lock_guard<std::recursive_mutex> rhs_guard(rhs.m_collection_mutex,
218+
std::adopt_lock);
217219
m_break_loc_collection = rhs.m_break_loc_collection;
218220
}
219221
return *this;

0 commit comments

Comments
 (0)