Skip to content

Commit

Permalink
Fix static variable data race access (#3282)
Browse files Browse the repository at this point in the history
* Fix static variable data race access

Signed-off-by: jparisu <[email protected]>

* Fix rebase

Signed-off-by: jparisu <[email protected]>

---------

Signed-off-by: jparisu <[email protected]>
  • Loading branch information
jparisu committed Jun 21, 2023
1 parent b89013a commit 7d5fe85
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 8 deletions.
11 changes: 9 additions & 2 deletions include/fastdds/rtps/builtin/discovery/participant/PDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,15 @@ class PDP
*/
virtual void announceParticipantState(
bool new_change,
bool dispose = false,
WriteParams& wparams = WriteParams::WRITE_PARAM_DEFAULT) = 0;
bool dispose,
WriteParams& wparams) = 0;

/**
* \c announceParticipantState method without optional output parameter \c wparams .
*/
virtual void announceParticipantState(
bool new_change,
bool dispose = false);

//!Stop the RTPSParticipantAnnouncement (only used in tests).
virtual void stopParticipantAnnouncement();
Expand Down
13 changes: 10 additions & 3 deletions include/fastdds/rtps/builtin/discovery/participant/PDPSimple.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,19 @@ class PDPSimple : public PDP
* Force the sending of our local DPD to all remote RTPSParticipants and multicast Locators.
* @param new_change If true a new change (with new seqNum) is created and sent; if false the last change is re-sent
* @param dispose Sets change kind to NOT_ALIVE_DISPOSED_UNREGISTERED
* @param wparams allows to identify the change
* @param[in, out] wparams allows to identify the change
*/
void announceParticipantState(
bool new_change,
bool dispose = false,
WriteParams& wparams = WriteParams::WRITE_PARAM_DEFAULT) override;
bool dispose,
WriteParams& wparams) override;

/**
* \c announceParticipantState method without optional output parameter \c wparams .
*/
void announceParticipantState(
bool new_change,
bool dispose = false) override;

/**
* This method assigns remote endpoints to the builtin endpoints defined in this protocol. It also calls
Expand Down
10 changes: 9 additions & 1 deletion include/fastdds/rtps/common/WriteParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,23 @@ class RTPS_DllAPI WriteParams
return *this;
}

static WriteParams WRITE_PARAM_DEFAULT;

/**
* Default value for methods receiving a WriteParams.
*
* Will contain the following values on its members:
* - sample_identity: Invalid SampleIdentity
* - related_sample_identity: Invalid SampleIdentity
* - source_timestamp: Invalid Time_t
*
* @note This should not return a reference to the static value if this value is meant to be
* read and written from different threads.
*/
static WriteParams WRITE_PARAM_DEFAULT;
static WriteParams write_params_default() noexcept
{
return WriteParams();
}

private:

Expand Down
8 changes: 8 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,14 @@ bool PDP::enable()
return builtin_endpoints_->enable_pdp_readers(mp_RTPSParticipant);
}

void PDP::announceParticipantState(
bool new_change,
bool dispose /* = false */)
{
WriteParams __wp = WriteParams::write_params_default();
announceParticipantState(new_change, dispose, __wp);
}

void PDP::announceParticipantState(
RTPSWriter& writer,
WriterHistory& history,
Expand Down
7 changes: 6 additions & 1 deletion src/cpp/rtps/builtin/discovery/participant/PDPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ class PDPClient : public PDP
* @param new_change If true a new change (with new seqNum) is created and sent;
* if false the last change is re-sent
* @param dispose Sets change kind to NOT_ALIVE_DISPOSED_UNREGISTERED
* @param wparams allows to identify the change
* @param wparams allows to identify the change [unused]
*
* @warning this method uses the static variable reference as it does not use the parameter \c wparams
* and this avoids a creation of an object WriteParams.
* However, if in future versions this method uses this argument, it must change to the function
* \c write_params_default for thread safety reasons.
*/
void announceParticipantState(
bool new_change,
Expand Down
7 changes: 6 additions & 1 deletion src/cpp/rtps/builtin/discovery/participant/PDPServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ class PDPServer : public fastrtps::rtps::PDP
* Force the sending of our local PDP to all servers
* @param new_change If true a new change (with new seqNum) is created and sent; if false the last change is re-sent
* @param dispose Sets change kind to NOT_ALIVE_DISPOSED_UNREGISTERED
* @param wparams allows to identify the change
* @param wparams allows to identify the change [unused]
*
* @warning this method uses the static variable reference as it does not use the parameter \c wparams
* and this avoids a creation of an object WriteParams.
* However, if in future versions this method uses this argument, it must change to the function
* \c write_params_default for thread safety reasons.
*/
void announceParticipantState(
bool new_change,
Expand Down
8 changes: 8 additions & 0 deletions src/cpp/rtps/builtin/discovery/participant/PDPSimple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ bool PDPSimple::updateInfoMatchesEDP()
return dynamic_cast<EDPStatic*>(mp_EDP) != nullptr;
}

void PDPSimple::announceParticipantState(
bool new_change,
bool dispose /* = false */)
{
WriteParams __wp = WriteParams::write_params_default();
announceParticipantState(new_change, dispose, __wp);
}

void PDPSimple::announceParticipantState(
bool new_change,
bool dispose,
Expand Down

0 comments on commit 7d5fe85

Please sign in to comment.