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

Make use of error return value in decrement_context_impl_ref_count #488

Merged
merged 2 commits into from Nov 23, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions rmw_fastrtps_shared_cpp/src/init_rmw_context_impl.cpp
Expand Up @@ -102,6 +102,7 @@ rmw_fastrtps_shared_cpp::decrement_context_impl_ref_count(rmw_context_t * contex
delete common_context;
context->impl->common = nullptr;
context->impl->participant_info = nullptr;
return ret;
}
return RMW_RET_OK;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way I think we could make this a bit clearer is to do a slight refactor of this method to move the context->impl->count != 0 check to the top of the method. That is, the start of the method would look something like:

std::lock_guard<std::mutex> guard(context->impl->mutex);
context->impl->count--;
if (context->impl->count > 0) {
  return RMW_RET_OK;
}

// implicitly, the count is now 0, and we can do cleanup things.

(we would still need your fix to return ret here, but now I think it would be a bit more clear that you have to do so, and the lack of it would have been picked up by normal compiler flags)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love using early returns whenever possible. Fixed.

}