Skip to content

Commit

Permalink
Refs #16192. Use mutex instead of atomic.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
MiguelCompany committed Jan 9, 2023
1 parent 19a9f96 commit 805820a
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/cpp/fastdds/subscriber/ReadConditionImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

#include <algorithm>
#include <atomic>
#include <forward_list>
#include <memory>
#include <mutex>
Expand Down Expand Up @@ -45,7 +44,8 @@ class ReadConditionImpl : public std::enable_shared_from_this<ReadConditionImpl>
{
DataReaderImpl& data_reader_;
const StateFilter state_;
std::atomic<StateFilter> value_;
StateFilter value_;
mutable std::mutex value_mtx_;
std::recursive_mutex& mutex_;
std::forward_list<const ReadCondition*> conditions_;

Expand All @@ -63,7 +63,9 @@ class ReadConditionImpl : public std::enable_shared_from_this<ReadConditionImpl>
{
try
{
value_.store(data_reader_.get_last_mask_state());
auto value = data_reader_.get_last_mask_state();
std::lock_guard<std::mutex> _(value_mtx_);
value_ = value;
}
catch (std::runtime_error& e)
{
Expand Down Expand Up @@ -109,16 +111,8 @@ class ReadConditionImpl : public std::enable_shared_from_this<ReadConditionImpl>

bool get_trigger_value() const noexcept
{
try
{
return get_trigger_value(value_);
}
catch (std::runtime_error& e)
{
// DataReader not enabled yet
EPROSIMA_LOG_WARNING(READCONDITION, e.what());
return false;
}
std::lock_guard<std::mutex> _(value_mtx_);
return get_trigger_value(value_);
}

DataReader* get_datareader() const noexcept
Expand Down Expand Up @@ -221,7 +215,8 @@ class ReadConditionImpl : public std::enable_shared_from_this<ReadConditionImpl>
void set_trigger_value(
const StateFilter& value) noexcept
{
value_.store(value);
std::lock_guard<std::mutex> _(value_mtx_);
value_ = value;
}

/**
Expand Down

0 comments on commit 805820a

Please sign in to comment.