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
[Cpp] Added tryClaim method to concurrent ringbuffers. #1325
[Cpp] Added tryClaim method to concurrent ringbuffers. #1325
Conversation
It would be best if the implementations followed the same API semantics as we have for the Java |
a3e6ade
to
defcab0
Compare
aeron-client/src/test/cpp/concurrent/OneToOneRingBufferTest.cpp
Outdated
Show resolved
Hide resolved
Will do |
@mjpt777 could there be a review of this ? |
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.
There are two things that stand out:
- Usage of the
RecordDescriptor::makeHeader
to combinelength
andtype
fields together.
We have decided that it would be better if the C++ version was aligned with the Java and C implementations, i.e. it should read/writelength
andtype
as separate fields. OneToOneRingBuffer::claimCapacity
is not aligned with the Java implementation, i.e. in Java and in C we add an additionalHEADER_LENGTH
when computing therequiredCapacity
. This allows for pre-zeroing of the next header upon claim and thus we don't need to zero the memory in theread/controlledRead
methods.
Another thing to note is that the C++ and C implementations don't have the controlledRead
API.
Will fix this probably some time next week. Thanks for the input. |
Is this progressing? |
In the codebase my team is working on we would like to use
concurrent::ringbuffers
. For us,tryClaim
interface is preferred. I tried following you're code convetion as much as possible but reused thetryClaim
implementaion forwrite
methods(that way tryClaim also gets tested withwrite
).Unfortunately order of atomic writes for
oneToOneRingBuffer
was changed.Tail
gets written first and only after doesmessageHeader
get written. This could affect performance.In our implementation of
spsc
channel we provide the callback to thetryClaim
method which gets called with the claimed buffer. That waytail
gets written after themessageHeader
; wanting to stay within the convention of your codebase this PR does it by introducingRingBufferClaim
class.Edit: As per @mjpt777's suggestion refactored the code to reflect Java
RingBuffer
s.