public class Sequence extends 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.
Modifier and Type | Field and Description |
---|---|
protected long |
p1 |
protected long |
p10 |
protected long |
p11 |
protected long |
p12 |
protected long |
p13 |
protected long |
p14 |
protected long |
p15 |
protected long |
p2 |
protected long |
p3 |
protected long |
p4 |
protected long |
p5 |
protected long |
p6 |
protected long |
p7 |
protected long |
p9 |
protected long |
value |
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.
|
String |
toString() |
protected long p9
protected long p10
protected long p11
protected long p12
protected long p13
protected long p14
protected long p15
protected volatile long value
protected long p1
protected long p2
protected long p3
protected long p4
protected long p5
protected long p6
protected long p7
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.Copyright © 2022. All rights reserved.