Skip to content

Commit

Permalink
Don't add separate mutex for relayAddrs.
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Beardsworth <[email protected]>
  • Loading branch information
mbeards committed May 15, 2024
1 parent fc5c2d5 commit 74139f0
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions include/gz/transport/Discovery.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
#include <map>
#include <memory>
#include <mutex>
#include <shared_mutex>
#include <string>
#include <thread>
#include <vector>
Expand Down Expand Up @@ -745,7 +744,7 @@ namespace gz
/// \param[in] _ip New IP address.
public: void AddRelayAddress(const std::string &_ip)
{
std::lock_guard<std::shared_mutex> lock(this->relayAddrsMutex);
std::lock_guard<std::mutex> lock(this->mutex);
// Sanity check: Make sure that this IP address is not already saved.
for (auto const &addr : this->relayAddrs)
{
Expand All @@ -768,7 +767,7 @@ namespace gz
{
std::vector<std::string> result;

std::shared_lock<std::shared_mutex> lock(this->relayAddrsMutex);
std::lock_guard<std::mutex> lock(this->mutex);

for (auto const &addr : this->relayAddrs) {
result.push_back(inet_ntoa(addr.sin_addr));
Expand Down Expand Up @@ -1291,7 +1290,7 @@ namespace gz
if (_msg.SerializeToArray(buffer + sizeof(msgSize), msgSize))
{
// Send the discovery message to the unicast relays.
std::shared_lock<std::shared_mutex> lock(this->relayAddrsMutex);
std::lock_guard<std::mutex> lock(this->mutex);

for (const auto &sockAddr : this->relayAddrs)
{
Expand Down Expand Up @@ -1554,9 +1553,6 @@ namespace gz
/// \brief Collection of socket addresses used as remote relays.
private: std::vector<sockaddr_in> relayAddrs;

/// \brief Mutex to guarantee exclusive write access to relayAddrs.
private: mutable std::shared_mutex relayAddrsMutex;

/// \brief Mutex to guarantee exclusive access between the threads.
private: mutable std::mutex mutex;

Expand Down

0 comments on commit 74139f0

Please sign in to comment.