Skip to content

Commit

Permalink
Keep signature of Node::Shared to maintain ABI stability
Browse files Browse the repository at this point in the history
`Node::Shared` is a private function but it's used in `details/Node.hh`
in templates which means there could be calls to `Node::Shared` embedded
in other libraries. Since we're mainly tracking the number of `Node`
instances, and since `Node::Shared` is private, it's okay to use raw pointers
internal use.

Signed-off-by: Addisu Z. Taddese <[email protected]>
  • Loading branch information
azeey committed Mar 16, 2024
1 parent 4d836cd commit 5bcb60f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/gz/transport/Node.hh
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ namespace gz
/// \brief Get a pointer to the shared node (singleton shared by all the
/// nodes).
/// \return The pointer to the shared node.
private: std::shared_ptr<NodeShared> Shared() const;
private: NodeShared *Shared() const;

/// \brief Get the UUID of this node.
/// \return The node UUID.
Expand Down
4 changes: 2 additions & 2 deletions include/gz/transport/NodeShared.hh
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ namespace gz
const std::string &_topic) const;

/// \brief Constructor.
public: NodeShared();
protected: NodeShared();

/// \brief Destructor.
public: virtual ~NodeShared();
protected: virtual ~NodeShared();

/// \brief Initialize all sockets.
/// \return True when success or false otherwise. This function might
Expand Down
4 changes: 2 additions & 2 deletions src/Node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,9 @@ bool Node::EnableStats(const std::string &_topic, bool _enable,
}

//////////////////////////////////////////////////
std::shared_ptr<NodeShared> Node::Shared() const
NodeShared *Node::Shared() const
{
return this->dataPtr->shared;
return this->dataPtr->shared.get();
}

//////////////////////////////////////////////////
Expand Down
5 changes: 3 additions & 2 deletions src/NodeShared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ std::shared_ptr<NodeShared> NodeShared::Instance()
// is not shared between different processes.
static std::weak_ptr<NodeShared> nodeSharedWeak;

auto nodeShared = nodeSharedWeak.lock();
std::shared_ptr<NodeShared> nodeShared = nodeSharedWeak.lock();
if (nodeShared)
return nodeShared;

nodeShared = std::make_shared<NodeShared>();
class MakeSharedEnabler : public NodeShared {};
nodeShared = std::make_shared<MakeSharedEnabler>();
nodeSharedWeak = nodeShared;
return nodeShared;
}
Expand Down

0 comments on commit 5bcb60f

Please sign in to comment.