Improved naming, removed improbable condition (which needs to be verified).
diff --git a/single_sequencer.go b/single_sequencer.go
index d576cf4..541beb4 100644
--- a/single_sequencer.go
+++ b/single_sequencer.go
@@ -1,16 +1,16 @@
package main
func (this *SingleProducerSequencer) Next(slots int64) int64 {
- current, gate := this.current, this.gate
+ current, cachedGate := this.current, this.cachedGate
next := current + slots
wrap := next - this.ringSize
- if wrap > gate || gate > current {
+ if wrap > cachedGate /*|| cachedGate > current*/ {
min, last := int64(0), this.last
for wrap > min {
min = last.Load()
}
- this.gate = min
+ this.cachedGate = min
}
this.current = next
@@ -23,18 +23,18 @@
func NewSingleProducerSequencer(cursor *Sequence, ringSize int32, last Barrier) *SingleProducerSequencer {
return &SingleProducerSequencer{
- current: InitialSequenceValue,
- gate: InitialSequenceValue,
- cursor: cursor,
- ringSize: int64(ringSize),
- last: last,
+ current: InitialSequenceValue,
+ cachedGate: InitialSequenceValue,
+ cursor: cursor,
+ ringSize: int64(ringSize),
+ last: last,
}
}
type SingleProducerSequencer struct {
- current int64
- gate int64
- cursor *Sequence
- ringSize int64
- last Barrier
+ current int64
+ cachedGate int64
+ cursor *Sequence
+ ringSize int64
+ last Barrier
}