Skip to content

Commit

Permalink
fix: decrement borrowed_publisher_num before ros2 publish (#334)
Browse files Browse the repository at this point in the history
fix/dec_brw_pub_num_earlier

Signed-off-by: Koichi98 <koichi.imai.2@tier4.jp>
  • Loading branch information
Koichi98 authored Jan 24, 2025
1 parent b238640 commit f161095
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/agnocastlib/include/agnocast_publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,18 @@ class Publisher
exit(EXIT_FAILURE);
}

publish_core(topic_name_, publisher_pid_, message.get_timestamp(), opened_mqs_);
// We need to decrement borrowed_publisher_num before ros2_publish, otherwise the buffers used
// for ROS2 serialization will also use shared memory. Since we don't need to store any
// additional data in shared memory after the agnocast publish operation, here is the ideal
// point to decrement.
decrement_borrowed_publisher_num();

if (do_always_ros2_publish_ || ros2_publisher_->get_subscription_count() > 0) {
const MessageT * raw = message.get();
ros2_publisher_->publish(*raw);
}

publish_core(topic_name_, publisher_pid_, message.get_timestamp(), opened_mqs_);
message.reset();
decrement_borrowed_publisher_num();
}

uint32_t get_subscription_count() const
Expand Down

0 comments on commit f161095

Please sign in to comment.