Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15174] Add new CMake option to allow users to enforce use of our third party shared_mutex #2846

Merged
merged 8 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ endif()

option(SQLITE3_SUPPORT "Activate SQLITE3 support" ON)

option(USE_THIRDPARTY_SHARED_MUTEX [=[
Forces the use of a Boost-based shared_mutex implementation
instead of the framework one. Useful to cope with issues on
framework implementations like misguided sanitizer reports.
This implementation will be used by default on frameworks
lacking the shared_mutex feature like those not fulfilling
C++17.
]=] OFF)

###############################################################################
# SHM as Default transport
###############################################################################
Expand Down
2 changes: 2 additions & 0 deletions include/fastrtps/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#define HAVE_SQLITE3 @HAVE_SQLITE3@
#endif /* ifndef HAVE_SQLITE3 */

// Using thirdparty shared_mutex
#cmakedefine01 USE_THIRDPARTY_SHARED_MUTEX

// TLS support
#ifndef TLS_FOUND
Expand Down
16 changes: 13 additions & 3 deletions include/fastrtps/utils/shared_mutex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@
#ifndef _UTILS_SHARED_MUTEX_HPP_
#define _UTILS_SHARED_MUTEX_HPP_

#ifndef USE_THIRDPARTY_SHARED_MUTEX
# if defined(_MSC_VER) && _MSVC_LANG < 202302L
# pragma message("warning: USE_THIRDPARTY_SHARED_MUTEX not defined. By default use framework version.")
# else
# warning "USE_THIRDPARTY_SHARED_MUTEX not defined. By default use framework version."
# endif // if defined(_MSC_VER) && _MSVC_LANG < 202302L
# define USE_THIRDPARTY_SHARED_MUTEX 0
#endif // ifndef USE_THIRDPARTY_SHARED_MUTEX

#if defined(__has_include) && __has_include(<version>)
# include <version>
#endif // if defined(__has_include) && __has_include(<version>)

// Detect if the share_mutex feature is available
#if defined(__has_include) && __has_include(<version>) && !defined(__cpp_lib_shared_mutex) || \
/* allow users to ignore shared_mutex framework implementation */ \
(~USE_THIRDPARTY_SHARED_MUTEX + 1) || \
/* deprecated procedure if the good one is not available*/ \
( !(defined(__has_include) && __has_include(<version>)) && \
!(defined(HAVE_CXX17) && HAVE_CXX17) && __cplusplus < 201703 )
Expand Down Expand Up @@ -353,9 +364,8 @@ shared_lock<Mutex>::try_lock()

namespace eprosima {

using shared_mutex = std::shared_mutex;
template< class Mutex >
using shared_lock = std::shared_lock<Mutex>;
using std::shared_mutex;
using std::shared_lock;

} //namespace eprosima

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,10 @@ endif()

install(TARGETS ${PROJECT_NAME} eProsima_atomic
EXPORT ${PROJECT_NAME}-${FASTDDS_LINKING}-targets
COMPONENT libraries
RUNTIME DESTINATION ${BIN_INSTALL_DIR}${MSVCARCH_DIR_EXTENSION}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}${MSVCARCH_DIR_EXTENSION}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}${MSVCARCH_DIR_EXTENSION}
COMPONENT libraries
)

export(TARGETS ${PROJECT_NAME} eProsima_atomic FILE ${PROJECT_BINARY_DIR}/cmake/config/${PROJECT_NAME}-${FASTDDS_LINKING}-targets.cmake)
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/rtps/participant/RTPSParticipantImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
#include <mutex>
#include <sys/types.h>

#include <fastrtps/utils/Semaphore.h>
#include <fastrtps/utils/shared_mutex.hpp>

#if defined(_WIN32)
#include <process.h>
#else
Expand Down Expand Up @@ -68,6 +65,9 @@
#include <rtps/security/SecurityManager.h>
#endif // if HAVE_SECURITY

#include <fastrtps/utils/Semaphore.h>
#include <fastrtps/utils/shared_mutex.hpp>

namespace eprosima {

namespace fastdds {
Expand Down
5 changes: 5 additions & 0 deletions versions.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Version 2.7.1
-------------

* Added a new CMake option to allow users to force the use of our third party shared_mutex

Version 2.7.0
-------------

Expand Down