Skip to content

Commit

Permalink
[Java] Use storeStoreFence in HeaderWriter now VarHandle is available.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Sep 19, 2024
1 parent 25c6b60 commit 23583f7
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package io.aeron.logbuffer;

import org.agrona.UnsafeAccess;
import org.agrona.concurrent.UnsafeBuffer;

import java.lang.invoke.VarHandle;
import java.nio.ByteOrder;

import static java.lang.Integer.reverseBytes;
Expand Down Expand Up @@ -82,14 +82,14 @@ public static HeaderWriter newInstance(final UnsafeBuffer defaultHeader)
public void write(final UnsafeBuffer termBuffer, final int offset, final int length, final int termId)
{
termBuffer.putLongOrdered(offset + FRAME_LENGTH_FIELD_OFFSET, versionFlagsType | ((-length) & 0xFFFF_FFFFL));
UnsafeAccess.UNSAFE.storeFence();
VarHandle.storeStoreFence();

termBuffer.putLong(offset + TERM_OFFSET_FIELD_OFFSET, sessionId | offset);
termBuffer.putLong(offset + STREAM_ID_FIELD_OFFSET, (((long)termId) << 32) | streamId);
}
}

class NativeBigEndianHeaderWriter extends HeaderWriter
final class NativeBigEndianHeaderWriter extends HeaderWriter
{
NativeBigEndianHeaderWriter(final UnsafeBuffer defaultHeader)
{
Expand All @@ -103,7 +103,7 @@ public void write(final UnsafeBuffer termBuffer, final int offset, final int len
{
termBuffer.putLongOrdered(
offset + FRAME_LENGTH_FIELD_OFFSET, ((((long)reverseBytes(-length))) << 32) | versionFlagsType);
UnsafeAccess.UNSAFE.storeFence();
VarHandle.storeStoreFence();

termBuffer.putLong(offset + TERM_OFFSET_FIELD_OFFSET, ((((long)reverseBytes(offset))) << 32) | sessionId);
termBuffer.putLong(offset + STREAM_ID_FIELD_OFFSET, streamId | (reverseBytes(termId) & 0xFFFF_FFFFL));
Expand Down

0 comments on commit 23583f7

Please sign in to comment.