Skip to content

Commit

Permalink
do not throw exception if trying to dequeue an empty intra-process bu…
Browse files Browse the repository at this point in the history
…ffer (#2061)

Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>

Signed-off-by: Alberto Soragna <alberto.soragna@gmail.com>
  • Loading branch information
alsora authored Dec 21, 2022
1 parent 9c1c989 commit 3fb012e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ class RingBufferImplementation : public BufferImplementationBase<BufferT>
std::lock_guard<std::mutex> lock(mutex_);

if (!has_data_()) {
RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), "Calling dequeue on empty intra-process buffer");
throw std::runtime_error("Calling dequeue on empty intra-process buffer");
return BufferT();
}

auto request = std::move(ring_buffer_[read_index_]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ class SubscriptionIntraProcess

if (any_callback_.use_take_shared_method()) {
shared_msg = this->buffer_->consume_shared();
if (!shared_msg) {
return nullptr;
}
} else {
unique_msg = this->buffer_->consume_unique();
if (!unique_msg) {
return nullptr;
}
}
return std::static_pointer_cast<void>(
std::make_shared<std::pair<ConstMessageSharedPtr, MessageUniquePtr>>(
Expand Down Expand Up @@ -138,7 +144,7 @@ class SubscriptionIntraProcess
execute_impl(std::shared_ptr<void> & data)
{
if (!data) {
throw std::runtime_error("'data' is empty");
return;
}

rmw_message_info_t msg_info;
Expand Down

0 comments on commit 3fb012e

Please sign in to comment.