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

Fix warnings and segfaults on Win32 builds #1982

Merged
merged 4 commits into from
May 21, 2021
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
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 @@ -333,7 +333,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
4 changes: 2 additions & 2 deletions src/cpp/rtps/builtin/discovery/participant/PDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ void PDP::initializeParticipantProxyData(
// Set participant type property
std::stringstream participant_type;
participant_type << mp_RTPSParticipant->getAttributes().builtin.discovery_config.discoveryProtocol;
participant_data->m_properties.push_back(std::pair<std::string,
std::string>({fastdds::dds::parameter_property_participant_type, participant_type.str()}));
auto ptype = participant_type.str();
participant_data->m_properties.push_back(fastdds::dds::parameter_property_participant_type, ptype);
}

bool PDP::initPDP(
Expand Down