Skip to content

Commit

Permalink
Add custom implementations for readVolatileShort(Object, offset), wri…
Browse files Browse the repository at this point in the history
…teVolatileShort(Object, offset) and readVolatileInt(Object, offset) for ARMMemory. Fix #416
  • Loading branch information
maxim-ponomarev committed Jun 22, 2022
1 parent 7676651 commit 9a2d852
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/net/openhft/chronicle/core/UnsafeMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,26 @@ public void writeVolatileShort(long address, short i16) {
}
}

@Override
public short readVolatileShort(Object object, long offset) {
assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), offset);
if ((offset & 0x1) == 0)
return super.readVolatileShort(object, offset);
UNSAFE.loadFence();
return super.readShort(object, offset);
}

@Override
public void writeVolatileShort(Object object, long offset, short i16) {
assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), offset);
if ((offset & 0x1) == 0) {
super.writeVolatileShort(object, offset, i16);
} else {
super.writeShort(object, offset, i16);
UNSAFE.storeFence();
}
}

@Override
public void writeFloat(long address, float f) {
assert SKIP_ASSERTIONS || address != 0;
Expand Down Expand Up @@ -1369,6 +1389,15 @@ public int readVolatileInt(long address) {
return super.readInt(address);
}

@Override
public int readVolatileInt(Object object, long offset) {
assert SKIP_ASSERTIONS || assertIfEnabled(Longs.nonNegative(), offset);
if (safeAlignedInt(offset))
return super.readVolatileInt(object, offset);
UNSAFE.loadFence();
return super.readInt(object, offset);
}

@Override
public float readVolatileFloat(long address) {
assert SKIP_ASSERTIONS || address != 0;
Expand Down

0 comments on commit 9a2d852

Please sign in to comment.