Skip to content

Commit

Permalink
Ensure correct boost singleton destruction order (#2356)
Browse files Browse the repository at this point in the history
* Refs 13287. Ensure correct boost singleton destruction order.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs 13288. Uncrustify.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs 13288. Fixed typo.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs 13288. Fixed link error on ListenerTests.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
(cherry picked from commit 80a44fe)

# Conflicts:
#	test/unittest/dds/status/CMakeLists.txt
  • Loading branch information
MiguelCompany authored and mergify-bot committed Dec 17, 2021
1 parent 8b3586c commit 96c1803
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/cpp/fastdds/domain/DomainParticipantFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
#include <statistics/fastdds/domain/DomainParticipantImpl.hpp>




// We include boost through this internal header, to ensure we use our custom boost config file
#include <utils/shared_memory/SharedMemSegment.hpp>
#include <boost/interprocess/sync/interprocess_mutex.hpp>

using namespace eprosima::fastrtps::xmlparser;

Expand Down Expand Up @@ -100,6 +101,27 @@ DomainParticipantFactory::~DomainParticipantFactory()

DomainParticipantFactory* DomainParticipantFactory::get_instance()
{
/*
* The first time an interprocess synchronization object is created by boost, a singleton is instantiated and
* its destructor is registered with std::atexit(&atexit_work).
*
* We need to ensure that the boost singleton is destroyed after the instance of DomainParticipantFactory, to
* ensure that the interprocess objects keep working until all the participants are destroyed.
*
* We achieve this behavior by having an static instance of an auxiliary struct that instantiates a synchronization
* object on the constructor, just to ensure that the boost singleton is instantiated before the
* DomainParticipantFactory.
*/
struct AuxiliaryBoostFunctor
{
AuxiliaryBoostFunctor()
{
boost::interprocess::interprocess_mutex mtx;
}

};
static AuxiliaryBoostFunctor boost_functor;

// Keep a reference to the topic payload pool to avoid it to be destroyed before our own instance
using pool_registry_ref = eprosima::fastrtps::rtps::TopicPayloadPoolRegistry::reference;
static pool_registry_ref topic_pool_registry = eprosima::fastrtps::rtps::TopicPayloadPoolRegistry::instance();
Expand Down
73 changes: 73 additions & 0 deletions test/unittest/dds/status/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,76 @@ if(NOT ((MSVC OR MSVC_IDE) AND EPROSIMA_INSTALLER))

endif()
endif()
<<<<<<< HEAD
=======

# External sources
if(TINYXML2_SOURCE_DIR)
list(APPEND LISTENERTESTS_SOURCE
${TINYXML2_SOURCE_DIR}/tinyxml2.cpp
)
endif()

include_directories(${TINYXML2_INCLUDE_DIR})

if(WIN32)
add_definitions(-D_WIN32_WINNT=0x0601)
endif()

add_executable(ListenerTests ${LISTENERTESTS_SOURCE})
target_compile_definitions(ListenerTests PRIVATE FASTRTPS_NO_LIB
BOOST_ASIO_STANDALONE
ASIO_STANDALONE
ASIO_DISABLE_VISIBILITY
SQLITE_WIN32_GETVERSIONEX=0
$<$<AND:$<BOOL:${ANDROID}>,$<NOT:$<BOOL:${HAVE_CXX14}>>,$<NOT:$<BOOL:${HAVE_CXX1Y}>>>:ASIO_DISABLE_STD_STRING_VIEW>
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
$<$<BOOL:${WIN32}>:_ENABLE_ATOMIC_ALIGNMENT_FIX>
)
target_include_directories(ListenerTests PRIVATE
${Asio_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/test/mock/rtps/DataSharingPayloadPool
${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSReader
${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSWriter
${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSDomain
${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSDomainImpl
${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSParticipant
${PROJECT_SOURCE_DIR}/test/mock/rtps/RTPSParticipantImpl
${PROJECT_SOURCE_DIR}/test/mock/rtps/Endpoint
${PROJECT_SOURCE_DIR}/test/mock/rtps/PDP
${PROJECT_SOURCE_DIR}/test/mock/rtps/PDPSimple
${PROJECT_SOURCE_DIR}/test/mock/rtps/StatefulWriter
${PROJECT_SOURCE_DIR}/test/mock/rtps/StatelessWriter
${PROJECT_SOURCE_DIR}/test/mock/rtps/StatefulReader
${PROJECT_SOURCE_DIR}/test/mock/rtps/StatelessReader
${PROJECT_SOURCE_DIR}/test/mock/rtps/WriterHistory
${PROJECT_SOURCE_DIR}/test/mock/rtps/ReaderHistory
${PROJECT_SOURCE_DIR}/test/mock/rtps/ResourceEvent
${PROJECT_SOURCE_DIR}/test/mock/rtps/TimedEvent
${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPTransportDescriptor
${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv4TransportDescriptor
${PROJECT_SOURCE_DIR}/test/mock/rtps/UDPv6TransportDescriptor
${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPTransportDescriptor
${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPv4TransportDescriptor
${PROJECT_SOURCE_DIR}/test/mock/rtps/TCPv6TransportDescriptor
${PROJECT_SOURCE_DIR}/test/mock/rtps/SharedMemTransportDescriptor
${PROJECT_SOURCE_DIR}/test/mock/rtps/TypeLookupManager
${PROJECT_SOURCE_DIR}/test/mock/rtps/WLP
${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include
${PROJECT_SOURCE_DIR}/src/cpp
${THIRDPARTY_BOOST_INCLUDE_DIR}
)

target_link_libraries(ListenerTests fastcdr foonathan_memory
${TINYXML2_LIBRARY}
GTest::gmock
${CMAKE_DL_LIBS}
${THIRDPARTY_BOOST_LINK_LIBS}
)
if(MSVC OR MSVC_IDE)
target_link_libraries(ListenerTests iphlpapi Shlwapi ws2_32)
endif()

add_gtest(ListenerTests SOURCES ${LISTENERTESTS_SOURCE})
>>>>>>> 80a44fe34 (Ensure correct boost singleton destruction order (#2356))

0 comments on commit 96c1803

Please sign in to comment.