Skip to content

Commit

Permalink
Make ClientData thread-safe (#293)
Browse files Browse the repository at this point in the history
* Make ClientData thread-safe

* Handle queries in flight

* Address some feedback

* Fix service client type check

* fix tracking of num in flight without UB

* Additional fixes for yadu/raii-client. (#304)

* Additional fixes for yadu/raii-client.

* Apply suggestions from code review

* Fixups.

* Fix -Wnon-pod-varargs

* Make PublisherData::copy_gid have the same signatures as others.

This just makes it more consistent with the rest of the
APIs.

* Add api to init client

* Vastly simplify handling of in-flight ClientData.

We basically use the pointer as a key to lookup the
shared_ptr, and then always use the shared_ptr.  That
ensures that even if the pointer was dropped from the
node while the client callback is operating, it will
still be valid and won't be destroyed until that method
returns.

Signed-off-by: Yadunund <[email protected]>
Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
Yadunund authored Nov 12, 2024
1 parent 00d8554 commit 91edead
Show file tree
Hide file tree
Showing 15 changed files with 901 additions and 807 deletions.
2 changes: 1 addition & 1 deletion rmw_zenoh_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ add_library(rmw_zenoh_cpp SHARED
src/detail/logging.cpp
src/detail/message_type_support.cpp
src/detail/qos.cpp
src/detail/rmw_client_data.cpp
src/detail/rmw_context_impl_s.cpp
src/detail/rmw_data_types.cpp
src/detail/rmw_publisher_data.cpp
src/detail/rmw_node_data.cpp
src/detail/rmw_service_data.cpp
Expand Down
9 changes: 4 additions & 5 deletions rmw_zenoh_cpp/src/detail/graph_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#include "graph_cache.hpp"
#include "logging_macros.hpp"
#include "rmw_data_types.hpp"

namespace rmw_zenoh_cpp
{
Expand Down Expand Up @@ -1182,15 +1181,15 @@ rmw_ret_t GraphCache::get_entities_info_by_topic(

///=============================================================================
rmw_ret_t GraphCache::service_server_is_available(
const char * service_name,
const char * service_type,
const liveliness::TopicInfo & client_topic_info,
bool * is_available) const
{
*is_available = false;
std::lock_guard<std::mutex> lock(graph_mutex_);
GraphNode::TopicMap::const_iterator service_it = graph_services_.find(service_name);
GraphNode::TopicMap::const_iterator service_it = graph_services_.find(client_topic_info.name_);
if (service_it != graph_services_.end()) {
GraphNode::TopicTypeMap::const_iterator type_it = service_it->second.find(service_type);
GraphNode::TopicTypeMap::const_iterator type_it =
service_it->second.find(client_topic_info.type_);
if (type_it != service_it->second.end()) {
for (const auto & [_, topic_data] : type_it->second) {
if (topic_data->subs_.size() > 0) {
Expand Down
3 changes: 1 addition & 2 deletions rmw_zenoh_cpp/src/detail/graph_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ class GraphCache final
rmw_topic_endpoint_info_array_t * endpoints_info) const;

rmw_ret_t service_server_is_available(
const char * service_name,
const char * service_type,
const liveliness::TopicInfo & client_topic_info,
bool * is_available) const;

/// Set a qos event callback for an entity from the current session.
Expand Down
Loading

0 comments on commit 91edead

Please sign in to comment.