-
Notifications
You must be signed in to change notification settings - Fork 16
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
iox-#64 Raw pointer API for publisher and subscriber #65
Conversation
ec18f5d
to
519766c
Compare
519766c
to
8574ab6
Compare
8574ab6
to
1046e75
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #65 +/- ##
==========================================
+ Coverage 48.27% 50.77% +2.50%
==========================================
Files 19 20 +1
Lines 1075 1154 +79
==========================================
+ Hits 519 586 +67
- Misses 556 568 +12 ☔ View full report in Codecov by Sentry. |
@phil-opp it took quite some time but I think it is now ready ... in case you still need it :) |
e91c1b0
to
42de1c0
Compare
b0f2a54
to
0f14f04
Compare
0f14f04
to
2656ffd
Compare
d280b0b
to
d78f308
Compare
/// Acquires the underlying payload pointer as `*mut` pointer. | ||
#[must_use] | ||
#[inline(always)] | ||
pub fn as_payload_mut_ptr(self) -> *mut T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be mut self
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe, in theory yes but I took inspiration from NonNull::as_ptr and NonNull::as_mut_ptr. Initially I tried to use NonNull
instead of an own type but then I discovered that I could not get a *const T
out of it and finally replicated NonNull
into these two structs. On the other hand, I already deviated from the NonNull
implementation by returning a *const T
for as_payload_ptr
. Just have to think what exactly the reason for the NonNull::as_mut_ptr
implementation could be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The counsel with the pillow helped. mut self
would even cause a warning. The method does no borrow but takes the ownership of the sample. The question is now why not using a reference? My guess is that taking the ownership and invoking a copy is more performant than using a reference. The struct has the the same size as a raw pointer and therefore passing by value or by reference has the same cost. Using the reference does add an indirection which is unnecessary in this case. It should not be a big penalty but I would keep the design similar to NonNull
@@ -207,6 +208,11 @@ impl<T: ?Sized> InactiveSubscriber<T> { | |||
pub fn subscription_state(&self) -> SubscribeState { | |||
self.ffi_sub.subscription_state() | |||
} | |||
|
|||
/// Releases a raw sample which will not be used anymore | |||
pub fn release_raw(&self, sample: RawSample<T>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when I call release_raw
multiple times with the same cloned sample? I think RawSample
can be cloned and copied.
I think it should be an unsafe
function and the user has to ensure that:
- the sample was not released before
- the sample was taken/acquired via the subscriber it is being released
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently nothing bad happens since the C++ code base takes care of this. iceoryx just prints a warning with [Warning]: ICEORYX error! POPO__CHUNK_SENDER_INVALID_CHUNK_TO_FREE_FROM_USER
. Since nothing bad happens I thought it does not need to be unsafe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouh, I thought that iceoryx would handle it in a more severe manner. In this particular case, I agree with you but it still feels weird and a little bit wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. There is quite a lot which can go wrong but all is handled in a graceful way. I don't know anymore why we chose this route at that time
Btw, I fixed all clippy warnings but I'm hesitant to commit them to this PR since it's adding additional 130 changes in 8 files. So I first wanted to ask if it's okay for you? I can also easily create a separate PR after this one is merged. Edit: Nevermind, I created a separate PR. |
@elfenpiff I fixed your findings and I'm going to merge this now. If there are still changes you would like to see I'm happy to create a follow up PT |
Pre-Review Checklist for the PR Author
rustfmt
iox-123-this-is-a-branch
)iox-#42 commit text
)task-list-completed
)Notes for Reviewer
This PR introduces a
RawSample
andRawSampleMut
in order to make the iceoryx-sys API more robust and ease the interoperability with C libraries from the high level API.Checklist for the PR Reviewer
Post-review Checklist for the PR Author
References