|
CARLA
|
Refcounted singleton DomainParticipant shared across all FastDDS publishers and subscribers in the process. More...
#include <FastDDSSharedParticipant.h>
Static Public Member Functions | |
| static eprosima::fastdds::dds::DomainParticipant * | acquire () |
| Increment the refcount and return the shared DomainParticipant. | |
| static void | release () |
| Decrement the refcount. | |
| static void | release_type (const std::string &type_name) |
| Release one use of type_name. | |
| static void | retain_type (const std::string &type_name) |
| Notify the singleton that one more endpoint is using type_name so that unregister_type() is deferred until the last user releases it. | |
Private Member Functions | |
| FastDDSSharedParticipant ()=delete | |
Static Private Attributes | |
| static std::mutex | _mutex |
| static eprosima::fastdds::dds::DomainParticipant * | _participant { nullptr } |
| static uint32_t | _refcount { 0u } |
| static std::unordered_map< std::string, uint32_t > | _type_refcounts |
Refcounted singleton DomainParticipant shared across all FastDDS publishers and subscribers in the process.
Using one DomainParticipant per publisher (the previous approach) caused a discovery storm on ROS2::Shutdown() when all N participants were destroyed back-to-back, triggering intermittent segfaults in remote rmw_fastrtps_cpp and rmw_cyclonedds_cpp clients. CycloneDDS already uses a process-lifetime shared participant (CycloneDDSSertype::carla_cdr_get_participant); this class mirrors that model for FastDDS.
Thread-safety: all methods acquire an internal mutex.
Definition at line 30 of file FastDDSSharedParticipant.h.
|
privatedelete |
|
static |
Increment the refcount and return the shared DomainParticipant.
Creates the participant on the first call. Returns nullptr on failure.
Definition at line 28 of file FastDDSSharedParticipant.cpp.
References _mutex, _participant, _refcount, carla::ros2::MiddlewareConfig::GetEffectiveDomainId(), and carla::log_error().
Referenced by carla::ros2::FastDDSPublisherMiddleware< T >::InitImpl(), and carla::ros2::FastDDSSubscriberMiddleware< S >::InitImpl().
|
static |
Decrement the refcount.
Destroys the participant when count reaches 0. Must be called exactly once for every successful acquire().
Definition at line 78 of file FastDDSSharedParticipant.cpp.
References _mutex, _participant, _refcount, _type_refcounts, and carla::log_error().
Referenced by carla::ros2::FastDDSPublisherMiddleware< T >::~FastDDSPublisherMiddleware(), and carla::ros2::FastDDSSubscriberMiddleware< S >::~FastDDSSubscriberMiddleware().
|
static |
Release one use of type_name.
Calls participant->unregister_type() when the count for that name drops to 0 (and the participant is still alive).
Definition at line 102 of file FastDDSSharedParticipant.cpp.
References _mutex, _participant, and _type_refcounts.
Referenced by carla::ros2::FastDDSPublisherMiddleware< T >::~FastDDSPublisherMiddleware(), and carla::ros2::FastDDSSubscriberMiddleware< S >::~FastDDSSubscriberMiddleware().
|
static |
Notify the singleton that one more endpoint is using type_name so that unregister_type() is deferred until the last user releases it.
Definition at line 97 of file FastDDSSharedParticipant.cpp.
References _mutex, and _type_refcounts.
Referenced by carla::ros2::FastDDSPublisherMiddleware< T >::InitImpl(), and carla::ros2::FastDDSSubscriberMiddleware< S >::InitImpl().
|
staticprivate |
Definition at line 51 of file FastDDSSharedParticipant.h.
Referenced by acquire(), release(), release_type(), and retain_type().
|
staticprivate |
Definition at line 52 of file FastDDSSharedParticipant.h.
Referenced by acquire(), release(), and release_type().
|
staticprivate |
Definition at line 53 of file FastDDSSharedParticipant.h.
|
staticprivate |
Definition at line 54 of file FastDDSSharedParticipant.h.
Referenced by release(), release_type(), and retain_type().