CARLA
Loading...
Searching...
No Matches
Static Public Member Functions | Private Member Functions | Static Private Attributes | List of all members
carla::ros2::FastDDSSharedParticipant Class Reference

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ FastDDSSharedParticipant()

carla::ros2::FastDDSSharedParticipant::FastDDSSharedParticipant ( )
privatedelete

Member Function Documentation

◆ acquire()

efd::DomainParticipant * carla::ros2::FastDDSSharedParticipant::acquire ( )
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().

◆ release()

void carla::ros2::FastDDSSharedParticipant::release ( )
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().

◆ release_type()

void carla::ros2::FastDDSSharedParticipant::release_type ( const std::string &  type_name)
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().

◆ retain_type()

void carla::ros2::FastDDSSharedParticipant::retain_type ( const std::string &  type_name)
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().

Member Data Documentation

◆ _mutex

std::mutex carla::ros2::FastDDSSharedParticipant::_mutex
staticprivate

Definition at line 51 of file FastDDSSharedParticipant.h.

Referenced by acquire(), release(), release_type(), and retain_type().

◆ _participant

efd::DomainParticipant * carla::ros2::FastDDSSharedParticipant::_participant { nullptr }
staticprivate

Definition at line 52 of file FastDDSSharedParticipant.h.

Referenced by acquire(), release(), and release_type().

◆ _refcount

uint32_t carla::ros2::FastDDSSharedParticipant::_refcount { 0u }
staticprivate

Definition at line 53 of file FastDDSSharedParticipant.h.

Referenced by acquire(), and release().

◆ _type_refcounts

std::unordered_map< std::string, uint32_t > carla::ros2::FastDDSSharedParticipant::_type_refcounts
staticprivate

Definition at line 54 of file FastDDSSharedParticipant.h.

Referenced by release(), release_type(), and retain_type().


The documentation for this class was generated from the following files: