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

Publisher dequeue changes #125

Merged
merged 2 commits into from
Aug 21, 2024
Merged

Publisher dequeue changes #125

merged 2 commits into from
Aug 21, 2024

Conversation

shuhaowu
Copy link
Contributor

It seems like publishing a ROS message is not passing the data to the executor so the executor sends the data during spin_once. That said, it might not be synchronous either as this is (middleware-)implementation defined. See rmw_publish_loaned_message. It seems like by default, FastDDS uses an async mode which uses an internal thread to send the data. That's fine with this code I think and we can basically treat that once we call publish, the message is basically sent.

Thus, instead of spin_once after stop is requested (due to signals), we simply drain the queue directly from Ros2ExecutorThread. This requires making Ros2ExecutorThreadto be a friend ofRos2Adapter. There's no issues with thread (as we are using a SPSC queue for the published message) because the TimerCallbackofRos2Adapteris executing as a part ofRos2ExecutorThreadanyway. Moving it out ofTimerCallbackand intoRos2ExecutorThread` is no different from a threading perspective.

Fixes #104

It seems like publishing a ROS message is not passing the data to the
executor so the executor sends the data during `spin_once`. That said,
it might not be synchronous either as this is
(middleware-)implementation defined. See
[`rmw_publish_loaned_message`][1]. It seems like by default, FastDDS
uses an async mode which uses an internal thread to send the data.
That's fine with this code I think and we can basically treat that
once we call publish, the message is basically sent.

Thus, instead of `spin_once` after stop is requested (due to signals), we
simply drain the queue directly from `Ros2ExecutorThread`. This requires
making `Ros2ExecutorThread` to be a friend of `Ros2Adapter`. There's no
issues with thread (as we are using a SPSC queue for the published
message) because the `TimerCallback` of `Ros2Adapter` is executing as a part
of `Ros2ExecutorThread` anyway. Moving it out of `TimerCallback` and into
`Ros2ExecutorThread` is no different from a threading perspective.

Fixes #104.

[1]: https://docs.ros.org/en/jazzy/p/rmw/generated/function_rmw_8h_1ab01da69d8613952343abd5d65107399a.html
@shuhaowu shuhaowu requested a review from stephanie-eng August 21, 2024 03:16
@shuhaowu shuhaowu merged commit 93254fc into master Aug 21, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants