Skip to content

Conversation

nnmm
Copy link
Contributor

@nnmm nnmm commented Jul 2, 2022

I tested it with CycloneDDS and it worked.

The only interesting things are

  • I stored a reference to the publisher/subscription in the message, so that the loan can be directly returned when the message is dropped (and it is guaranteed that the publisher/subscription still exists)
  • I made publish() a method on the LoanedMessage that takes no argument, since it can only be used with the publisher that was used to create it, and that publisher is stored inside the message. So this design statically guarantees that a loaned message cannot be published to the wrong publisher.

Closes #136

@nnmm nnmm force-pushed the loaned_message branch 3 times, most recently from bfeb3b6 to ae39b4b Compare July 2, 2022 13:21
@nnmm nnmm requested a review from a team July 2, 2022 14:06
@nnmm nnmm force-pushed the loaned_message branch from ae39b4b to 7e34625 Compare July 15, 2022 07:17
Copy link
Collaborator

@jhdcs jhdcs left a comment

Choose a reason for hiding this comment

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

One small comment tweak. However, I'm curious about how cloning might affect this... Is it possible to get a double-free error if you clone a loaned message, then drop both? Or am I just being paranoid?

if !self.msg_ptr.is_null() {
unsafe {
// SAFETY: These two pointers are valid, and the msg_ptr is not used afterwards.
rcl_return_loaned_message_from_publisher(
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if a user does something like .clone() a loaned message? Would that affect this?

{
fn drop(&mut self) {
unsafe {
rcl_return_loaned_message_from_subscription(
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if a user .clone()s a loaned message? Will that affect this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that would be bad, that's why loaned messages don't implement Clone.

@jhdcs jhdcs self-requested a review July 21, 2022 14:24
jhdcs
jhdcs previously approved these changes Jul 21, 2022
Copy link
Collaborator

@jhdcs jhdcs left a comment

Choose a reason for hiding this comment

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

My biggest concern was addressed in a comment, and the documentation change isn't worth holding up the PR.

jhdcs
jhdcs previously approved these changes Jul 22, 2022
@nnmm
Copy link
Contributor Author

nnmm commented Jul 23, 2022

@esteve Do you also want to have a look at this?

nnmm and others added 2 commits August 5, 2022 19:46
Co-authored-by: jhdcs <48914066+jhdcs@users.noreply.github.com>
@nnmm
Copy link
Contributor Author

nnmm commented Aug 5, 2022

@esteve Please review (or let me know if Jacob's review is sufficient for you).

Copy link
Collaborator

@esteve esteve left a comment

Choose a reason for hiding this comment

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

Great work!

@nnmm
Copy link
Contributor Author

nnmm commented Aug 16, 2022

Thanks! Don't be surprised if this fails on master; see #239 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for zero-copy pub/sub
3 participants