[Lldb-commits] [lldb] [lldb] Make Listener::m_broadcasters_mutex non-recursive (PR #97552)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 3 03:28:01 PDT 2024
https://github.com/labath created https://github.com/llvm/llvm-project/pull/97552
Follow-up to #97400. No changes apart from changing the type were necessary. The mutex was already not used recursively.
>From d183b37fdc4cda4f76b33b768a42e43368c68464 Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Wed, 3 Jul 2024 10:23:26 +0000
Subject: [PATCH] [lldb] Make Listener::m_broadcasters_mutex non-recursive
Follow-up to #97400. No changes apart from changing the type were
necessary. The mutex was already not used recursively.
---
lldb/include/lldb/Utility/Listener.h | 2 +-
lldb/source/Utility/Listener.cpp | 21 ++++++++-------------
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/lldb/include/lldb/Utility/Listener.h b/lldb/include/lldb/Utility/Listener.h
index daa7deb345f30..eec8af023f263 100644
--- a/lldb/include/lldb/Utility/Listener.h
+++ b/lldb/include/lldb/Utility/Listener.h
@@ -127,7 +127,7 @@ class Listener : public std::enable_shared_from_this<Listener> {
std::string m_name;
broadcaster_collection m_broadcasters;
- std::recursive_mutex m_broadcasters_mutex; // Protects m_broadcasters
+ std::mutex m_broadcasters_mutex; // Protects m_broadcasters
event_collection m_events;
std::mutex m_events_mutex; // Protects m_broadcasters and m_events
std::condition_variable m_events_condition;
diff --git a/lldb/source/Utility/Listener.cpp b/lldb/source/Utility/Listener.cpp
index 0b28cb5cdc642..6265c30af0d18 100644
--- a/lldb/source/Utility/Listener.cpp
+++ b/lldb/source/Utility/Listener.cpp
@@ -38,8 +38,7 @@ Listener::~Listener() {
void Listener::Clear() {
Log *log = GetLog(LLDBLog::Object);
- std::lock_guard<std::recursive_mutex> broadcasters_guard(
- m_broadcasters_mutex);
+ std::lock_guard<std::mutex> broadcasters_guard(m_broadcasters_mutex);
broadcaster_collection::iterator pos, end = m_broadcasters.end();
for (pos = m_broadcasters.begin(); pos != end; ++pos) {
Broadcaster::BroadcasterImplSP broadcaster_sp(pos->first.lock());
@@ -68,8 +67,7 @@ uint32_t Listener::StartListeningForEvents(Broadcaster *broadcaster,
// Scope for "locker"
// Tell the broadcaster to add this object as a listener
{
- std::lock_guard<std::recursive_mutex> broadcasters_guard(
- m_broadcasters_mutex);
+ std::lock_guard<std::mutex> broadcasters_guard(m_broadcasters_mutex);
Broadcaster::BroadcasterImplWP impl_wp(broadcaster->GetBroadcasterImpl());
m_broadcasters.insert(
std::make_pair(impl_wp, BroadcasterInfo(event_mask)));
@@ -99,8 +97,7 @@ uint32_t Listener::StartListeningForEvents(Broadcaster *broadcaster,
// Scope for "locker"
// Tell the broadcaster to add this object as a listener
{
- std::lock_guard<std::recursive_mutex> broadcasters_guard(
- m_broadcasters_mutex);
+ std::lock_guard<std::mutex> broadcasters_guard(m_broadcasters_mutex);
Broadcaster::BroadcasterImplWP impl_wp(broadcaster->GetBroadcasterImpl());
m_broadcasters.insert(std::make_pair(
impl_wp, BroadcasterInfo(event_mask, callback, callback_user_data)));
@@ -131,8 +128,7 @@ bool Listener::StopListeningForEvents(Broadcaster *broadcaster,
if (broadcaster) {
// Scope for "locker"
{
- std::lock_guard<std::recursive_mutex> broadcasters_guard(
- m_broadcasters_mutex);
+ std::lock_guard<std::mutex> broadcasters_guard(m_broadcasters_mutex);
m_broadcasters.erase(broadcaster->GetBroadcasterImpl());
}
// Remove the broadcaster from our set of broadcasters
@@ -147,8 +143,7 @@ bool Listener::StopListeningForEvents(Broadcaster *broadcaster,
void Listener::BroadcasterWillDestruct(Broadcaster *broadcaster) {
// Scope for "broadcasters_locker"
{
- std::lock_guard<std::recursive_mutex> broadcasters_guard(
- m_broadcasters_mutex);
+ std::lock_guard<std::mutex> broadcasters_guard(m_broadcasters_mutex);
m_broadcasters.erase(broadcaster->GetBroadcasterImpl());
}
@@ -322,7 +317,7 @@ bool Listener::GetEvent(EventSP &event_sp, const Timeout<std::micro> &timeout) {
size_t Listener::HandleBroadcastEvent(EventSP &event_sp) {
size_t num_handled = 0;
- std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ std::lock_guard<std::mutex> guard(m_broadcasters_mutex);
Broadcaster *broadcaster = event_sp->GetBroadcaster();
if (!broadcaster)
return 0;
@@ -357,7 +352,7 @@ Listener::StartListeningForEventSpec(const BroadcasterManagerSP &manager_sp,
// The BroadcasterManager mutex must be locked before m_broadcasters_mutex to
// avoid violating the lock hierarchy (manager before broadcasters).
std::lock_guard<std::mutex> manager_guard(manager_sp->m_manager_mutex);
- std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ std::lock_guard<std::mutex> guard(m_broadcasters_mutex);
uint32_t bits_acquired = manager_sp->RegisterListenerForEventsNoLock(
this->shared_from_this(), event_spec);
@@ -379,7 +374,7 @@ bool Listener::StopListeningForEventSpec(const BroadcasterManagerSP &manager_sp,
// The BroadcasterManager mutex must be locked before m_broadcasters_mutex to
// avoid violating the lock hierarchy (manager before broadcasters).
std::lock_guard<std::mutex> manager_guard(manager_sp->m_manager_mutex);
- std::lock_guard<std::recursive_mutex> guard(m_broadcasters_mutex);
+ std::lock_guard<std::mutex> guard(m_broadcasters_mutex);
return manager_sp->UnregisterListenerForEventsNoLock(this->shared_from_this(),
event_spec);
}
More information about the lldb-commits
mailing list