CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
ros2
middleware
fastdds
FastDDSSharedParticipant.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma de Barcelona (UAB).
2
// This work is licensed under the terms of the MIT license.
3
// For a copy, see <https://opensource.org/licenses/MIT>.
4
5
#pragma once
6
7
#ifndef CARLA_ROS2_MIDDLEWARE_TESTING
8
9
#include <fastdds/dds/domain/DomainParticipant.hpp>
10
11
#include <cstdint>
12
#include <mutex>
13
#include <string>
14
#include <unordered_map>
15
16
namespace
carla
{
17
namespace
ros2
{
18
19
/// Refcounted singleton DomainParticipant shared across all FastDDS
20
/// publishers and subscribers in the process.
21
///
22
/// Using one DomainParticipant per publisher (the previous approach) caused a
23
/// discovery storm on ROS2::Shutdown() when all N participants were destroyed
24
/// back-to-back, triggering intermittent segfaults in remote rmw_fastrtps_cpp
25
/// and rmw_cyclonedds_cpp clients. CycloneDDS already uses a
26
/// process-lifetime shared participant (CycloneDDSSertype::carla_cdr_get_participant);
27
/// this class mirrors that model for FastDDS.
28
///
29
/// Thread-safety: all methods acquire an internal mutex.
30
class
FastDDSSharedParticipant
{
31
public
:
32
/// Increment the refcount and return the shared DomainParticipant.
33
/// Creates the participant on the first call. Returns nullptr on failure.
34
static
eprosima::fastdds::dds::DomainParticipant*
acquire
();
35
36
/// Decrement the refcount. Destroys the participant when count reaches 0.
37
/// Must be called exactly once for every successful acquire().
38
static
void
release
();
39
40
/// Notify the singleton that one more endpoint is using type_name so that
41
/// unregister_type() is deferred until the last user releases it.
42
static
void
retain_type
(
const
std::string& type_name);
43
44
/// Release one use of type_name. Calls participant->unregister_type() when
45
/// the count for that name drops to 0 (and the participant is still alive).
46
static
void
release_type
(
const
std::string& type_name);
47
48
private
:
49
FastDDSSharedParticipant
() =
delete
;
50
51
static
std::mutex
_mutex
;
52
static
eprosima::fastdds::dds::DomainParticipant*
_participant
;
53
static
uint32_t
_refcount
;
54
static
std::unordered_map<std::string, uint32_t>
_type_refcounts
;
55
};
56
57
}
// namespace ros2
58
}
// namespace carla
59
60
#endif
// !CARLA_ROS2_MIDDLEWARE_TESTING
carla::ros2::FastDDSSharedParticipant::release_type
static void release_type(const std::string &type_name)
Release one use of type_name.
Definition
FastDDSSharedParticipant.cpp:105
carla::ros2::FastDDSSharedParticipant::FastDDSSharedParticipant
FastDDSSharedParticipant()=delete
carla::ros2::FastDDSSharedParticipant::_refcount
static uint32_t _refcount
Definition
FastDDSSharedParticipant.h:53
carla::ros2::FastDDSSharedParticipant::_participant
static eprosima::fastdds::dds::DomainParticipant * _participant
Definition
FastDDSSharedParticipant.h:52
carla::ros2::FastDDSSharedParticipant::acquire
static eprosima::fastdds::dds::DomainParticipant * acquire()
Increment the refcount and return the shared DomainParticipant.
Definition
FastDDSSharedParticipant.cpp:28
carla::ros2::FastDDSSharedParticipant::_mutex
static std::mutex _mutex
Definition
FastDDSSharedParticipant.h:51
carla::ros2::FastDDSSharedParticipant::retain_type
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 ...
Definition
FastDDSSharedParticipant.cpp:100
carla::ros2::FastDDSSharedParticipant::_type_refcounts
static std::unordered_map< std::string, uint32_t > _type_refcounts
Definition
FastDDSSharedParticipant.h:54
carla::ros2::FastDDSSharedParticipant::release
static void release()
Decrement the refcount.
Definition
FastDDSSharedParticipant.cpp:81
carla::ros2
Definition
AutowareSteeringCompensation.h:15
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
Generated by
1.18.0