public class Sequence
extends java.lang.Object
Concurrent sequence class used for tracking the progress of the ring buffer and event processors. Support a number of concurrent operations including CAS and order writes.
Also attempts to be more efficient with regards to false sharing by adding padding around the volatile field.
Constructor and Description |
---|
Sequence()
Create a sequence initialised to -1.
|
Sequence(long initialValue)
Create a sequence with a specified initial value.
|
Modifier and Type | Method and Description |
---|---|
long |
addAndGet(long increment)
Atomically add the supplied value.
|
boolean |
compareAndSet(long expectedValue,
long newValue)
Perform a compare and set operation on the sequence.
|
long |
get()
Perform a volatile read of this sequence's value.
|
long |
incrementAndGet()
Atomically increment the sequence by one.
|
void |
set(long value)
Perform an ordered write of this sequence.
|
void |
setVolatile(long value)
Performs a volatile write of this sequence.
|
java.lang.String |
toString() |
public Sequence()
public Sequence(long initialValue)
initialValue
- The initial value for this sequence.public long get()
public void set(long value)
value
- The new value for the sequence.public void setVolatile(long value)
value
- The new value for the sequence.public boolean compareAndSet(long expectedValue, long newValue)
expectedValue
- The expected current value.newValue
- The value to update to.public long incrementAndGet()
public long addAndGet(long increment)
increment
- The value to add to the sequence.public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2011 - 2013 LMAX Ltd. All Rights Reserved.