Skip to content

Commit

Permalink
Fix warnings and segfaults on Win32 builds (#1982)
Browse files Browse the repository at this point in the history
* Refs 11606. Fixed alignment warnings.

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

* Refs 11606. Added ParameterPropertyList_t::push_back method receiving 2 const string refs.

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

* Refs 11606. Using new method on PDP and ParticipantProxyData.

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

* Refs 11606. Improve thread safety on DataSharingListener.

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

# Conflicts:
#	src/cpp/rtps/builtin/discovery/participant/PDP.cpp
  • Loading branch information
MiguelCompany authored and mergify-bot committed May 24, 2021
1 parent de05594 commit c582d8b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 30 deletions.
38 changes: 18 additions & 20 deletions include/fastdds/dds/core/policy/ParameterTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,27 +1301,25 @@ class ParameterPropertyList_t : public Parameter_t
bool push_back(
std::pair<std::string, std::string> p)
{
//Realloc if needed;
uint32_t size1 = (uint32_t) p.first.length() + 1;
uint32_t alignment1 = ((size1 + 3u) & ~3u) - size1;

uint32_t size2 = (uint32_t) p.second.length() + 1;
uint32_t alignment2 = ((size2 + 3u) & ~3u) - size2;
return push_back(p.first, p.second);
}

if (limit_size_ && (properties_.max_size < properties_.length +
size1 + alignment1 + 4 +
size2 + alignment2 + 4))
{
return false;
}
properties_.reserve(properties_.length +
size1 + alignment1 + 4 +
size2 + alignment2 + 4);
/**
* @brief Introduce a new property in the ParameterPropertyList
* @param key Key part of the new property
* @param value Value part of the new property
* @return true if it is introduced, false if not.
*/
bool push_back(
const std::string& key,
const std::string& value)
{
auto str1 = reinterpret_cast<const unsigned char*>(key.c_str());
uint32_t size1 = (uint32_t) key.length() + 1;
auto str2 = reinterpret_cast<const unsigned char*>(value.c_str());
uint32_t size2 = (uint32_t) value.length() + 1;

push_back_helper((fastrtps::rtps::octet*)p.first.c_str(), size1, alignment1);
push_back_helper((fastrtps::rtps::octet*)p.second.c_str(), size2, alignment2);
++Nproperties_;
return true;
return push_back(str1, size1, str2, size2);
}

/**
Expand Down Expand Up @@ -1636,7 +1634,7 @@ void set_proxy_property(
else
{
// if not exists add
properties.push_back(pair);
properties.push_back(pair.first, pair.second);
}
}

Expand Down
23 changes: 17 additions & 6 deletions src/cpp/rtps/DataSharing/DataSharingListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ void DataSharingListener::run()

void DataSharingListener::start()
{
std::lock_guard<std::mutex> guard(mutex_);

// Check the thread
bool was_running = is_running_.exchange(true);
if (was_running)
Expand All @@ -92,17 +94,26 @@ void DataSharingListener::start()

void DataSharingListener::stop()
{
// Notify the listening thread that is no longer running
bool was_running = is_running_.exchange(false);
if (!was_running)
std::thread* thr = nullptr;

{
return;
std::lock_guard<std::mutex> guard(mutex_);

// Notify the listening thread that is no longer running
bool was_running = is_running_.exchange(false);
if (!was_running)
{
return;
}

thr = listening_thread_;
listening_thread_ = nullptr;
}

// Notify the thread and wait for it to finish
notification_->notify();
listening_thread_->join();
delete listening_thread_;
thr->join();
delete thr;
}

void DataSharingListener::process_new_data ()
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/rtps/DataSharing/DataSharingNotification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DataSharingNotification

#pragma warning(push)
#pragma warning(disable:4324)
struct alignas (void*) Notification
struct alignas (uint64_t) Notification
{
//! CV to wait for new notifications
Segment::condition_variable notification_cv;
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/rtps/DataSharing/DataSharingPayloadPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class DataSharingPayloadPool : public IPayloadPool

#pragma warning(push)
#pragma warning(disable:4324)
class alignas (void*) PayloadNode
class alignas (uint64_t) PayloadNode
{

struct PayloadNodeMetaData
Expand Down Expand Up @@ -317,7 +317,7 @@ class DataSharingPayloadPool : public IPayloadPool

};

struct alignas (void*) PoolDescriptor
struct alignas (uint64_t) PoolDescriptor
{
uint32_t history_size; //< Number of payloads in the history
uint64_t notified_begin; //< The index of the oldest history entry already notified (ready to read)
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/rtps/builtin/data/ParticipantProxyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ void ParticipantProxyData::set_persistence_guid(
else
{
// if not exists add
m_properties.push_back(persistent_guid);
m_properties.push_back(persistent_guid.first, persistent_guid.second);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ void PDP::initializeParticipantProxyData(
participant_data->plugin_security_attributes_ = 0UL;
}
#endif // if HAVE_SECURITY
<<<<<<< HEAD
=======

// Set participant type property
std::stringstream participant_type;
participant_type << mp_RTPSParticipant->getAttributes().builtin.discovery_config.discoveryProtocol;
auto ptype = participant_type.str();
participant_data->m_properties.push_back(fastdds::dds::parameter_property_participant_type, ptype);
>>>>>>> d5f3559fb (Fix warnings and segfaults on Win32 builds (#1982))
}

bool PDP::initPDP(
Expand Down

0 comments on commit c582d8b

Please sign in to comment.