Created
December 13, 2012 12:49
-
-
Save nitsanw/4276162 to your computer and use it in GitHub Desktop.
VolatileLong
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private volatile long value; | |
private static final long valueOffset; | |
static { | |
try { | |
valueOffset = UnsafeAccess.unsafe.objectFieldOffset(VolatileLong.class.getDeclaredField("value")); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public void set(final long value) { | |
this.value = value; | |
} | |
public long get() { | |
return value; | |
} | |
public long directGet() { | |
return UnsafeAccess.unsafe.getLong(this, valueOffset); | |
} | |
public void directSet(final long value) { | |
UnsafeAccess.unsafe.putLong(this, valueOffset, value); | |
} | |
public void lazySet(final long value) { | |
UnsafeAccess.unsafe.putOrderedLong(this, valueOffset, value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment