-
Notifications
You must be signed in to change notification settings - Fork 436
Weaken memory ordering OneToOnRingBuffer #359
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,6 @@ | |
| import org.agrona.concurrent.ControlledMessageHandler; | ||
| import org.agrona.concurrent.MessageHandler; | ||
|
|
||
| import java.lang.invoke.VarHandle; | ||
|
|
||
| import static java.lang.Math.max; | ||
| import static org.agrona.BitUtil.align; | ||
| import static org.agrona.concurrent.ControlledMessageHandler.Action.*; | ||
|
|
@@ -100,8 +98,7 @@ public boolean write(final int msgTypeId, final DirectBuffer srcBuffer, final in | |
| return false; | ||
| } | ||
|
|
||
| buffer.putIntRelease(lengthOffset(recordIndex), -recordLength); | ||
| VarHandle.releaseFence(); | ||
| buffer.putIntOpaque(lengthOffset(recordIndex), -recordLength); | ||
|
|
||
| buffer.putBytes(encodedMsgOffset(recordIndex), srcBuffer, offset, length); | ||
| buffer.putInt(typeOffset(recordIndex), msgTypeId); | ||
|
|
@@ -127,8 +124,7 @@ public int tryClaim(final int msgTypeId, final int length) | |
| return recordIndex; | ||
| } | ||
|
|
||
| buffer.putIntRelease(lengthOffset(recordIndex), -recordLength); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also an opaque write for the record length. We do not care for any ordering guarantees. Only when the record is committed, a release store is needed which will order the stores to the record before it. |
||
| VarHandle.releaseFence(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The VarHandle.releaseFence can be dropped. THe only ordering that is needed is the release store of the (positive) record length when committing. This will order all the stores to the record before it. |
||
| buffer.putIntOpaque(lengthOffset(recordIndex), -recordLength); | ||
| buffer.putInt(typeOffset(recordIndex), msgTypeId); | ||
|
|
||
| return encodedMsgOffset(recordIndex); | ||
|
|
@@ -472,9 +468,6 @@ else if (requiredCapacity > toBufferEndLength) | |
| if (0 != padding) | ||
| { | ||
| buffer.putLong(0, 0L); | ||
| buffer.putIntRelease(lengthOffset(recordIndex), -padding); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to announce the negative length. The reading side will not read the record while the length is not positive. And there won't be any abort in this case. |
||
| VarHandle.releaseFence(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The releaseFence is not needed. The release store of the commit (so writing the positive length) will order the write of the message type, before it. |
||
|
|
||
| buffer.putInt(typeOffset(recordIndex), PADDING_MSG_TYPE_ID); | ||
| buffer.putIntRelease(lengthOffset(recordIndex), padding); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
For the actual claim (so writing the negative record length), only opaque is needed. Surrounding loads/stores do not need to be ordered. The content of the record can't be read (apart from the length) until the commit is done. The commit is performed using a release store and will make sure that all writes to the record are visible when the positive length is read by the reader.