Skip to content

Commit

Permalink
Fixed race condition between taking sample and updating counter. (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
richiware authored and clalancette committed Mar 22, 2019
1 parent c9e4965 commit fc4b27e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ class SubListener : public eprosima::fastrtps::SubscriberListener
}

void
data_taken()
data_taken(eprosima::fastrtps::Subscriber * sub)
{
std::lock_guard<std::mutex> lock(internalMutex_);

if (conditionMutex_ != nullptr) {
std::unique_lock<std::mutex> clock(*conditionMutex_);
--data_;
data_ = sub->getUnreadCount();
} else {
--data_;
data_ = sub->getUnreadCount();
}
}

Expand Down
4 changes: 2 additions & 2 deletions rmw_fastrtps_shared_cpp/src/rmw_take.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ _take(
data.is_cdr_buffer = false;
data.data = ros_message;
if (info->subscriber_->takeNextData(&data, &sinfo)) {
info->listener_->data_taken();
info->listener_->data_taken(info->subscriber_);

if (eprosima::fastrtps::rtps::ALIVE == sinfo.sampleKind) {
if (message_info) {
Expand Down Expand Up @@ -140,7 +140,7 @@ _take_serialized_message(
data.is_cdr_buffer = true;
data.data = &buffer;
if (info->subscriber_->takeNextData(&data, &sinfo)) {
info->listener_->data_taken();
info->listener_->data_taken(info->subscriber_);

if (eprosima::fastrtps::rtps::ALIVE == sinfo.sampleKind) {
auto buffer_size = static_cast<size_t>(buffer.getBufferSize());
Expand Down

0 comments on commit fc4b27e

Please sign in to comment.