Renamed internal variables.
diff --git a/shared_writer.go b/shared_writer.go
index 855249d..ec15c7f 100644
--- a/shared_writer.go
+++ b/shared_writer.go
@@ -6,30 +6,30 @@
)
type SharedWriter struct {
- capacity int64
- gate int64 // TODO: this will most likely need to be a cursor
- shift uint8
- committedSequences []int32
- readerBarrier Barrier
- writerCursor *Cursor
+ capacity int64
+ gate int64 // TODO: this will most likely need to be a cursor
+ shift uint8
+ committed []int32
+ upstream Barrier
+ reservation *Cursor
}
-func NewSharedWriter(writerCursor *Cursor, capacity int64, readerBarrier Barrier) *SharedWriter {
+func NewSharedWriter(reservation *Cursor, capacity int64, upstream Barrier) *SharedWriter {
assertPowerOfTwo(capacity)
shift := uint8(math.Log2(float64(capacity)))
- buffer := initializeCommittedSequences(capacity)
+ buffer := initializeCommittedBuffer(capacity)
return &SharedWriter{
- capacity: capacity,
- gate: InitialSequenceValue,
- shift: shift,
- committedSequences: buffer,
- readerBarrier: readerBarrier,
- writerCursor: writerCursor,
+ capacity: capacity,
+ gate: InitialSequenceValue,
+ shift: shift,
+ committed: buffer,
+ upstream: upstream,
+ reservation: reservation,
}
}
-func initializeCommittedSequences(capacity int64) []int32 {
+func initializeCommittedBuffer(capacity int64) []int32 {
buffer := make([]int32, capacity)
for i := range buffer {
buffer[i] = int32(InitialSequenceValue)
@@ -45,12 +45,12 @@
}
for {
- previous := this.writerCursor.Load()
+ previous := this.reservation.Load()
next := previous + count
wrap := next - this.capacity
if wrap > this.gate {
- min := this.readerBarrier.Load()
+ min := this.upstream.Load()
if wrap > min {
return 0, Gating
}
@@ -58,7 +58,7 @@
this.gate = min // doesn't matter which write wins, BUT will most likely need to be a Cursor
}
- if atomic.CompareAndSwapInt64(&this.writerCursor.value, previous, next) {
+ if atomic.CompareAndSwapInt64(&this.reservation.value, previous, next) {
return previous + 1, next
}
}
@@ -66,18 +66,18 @@
func (this *SharedWriter) Commit(lower, upper int64) {
for mask := this.capacity - 1; lower <= upper; lower++ {
- this.committedSequences[lower&mask] = int32(lower >> this.shift)
+ this.committed[lower&mask] = int32(lower >> this.shift)
}
}
func (this *SharedWriter) Load() int64 {
- upper := this.writerCursor.Load()
+ sequence := this.reservation.Load()
- for mask := this.capacity - 1; upper >= 0; upper-- {
- if this.committedSequences[upper&mask] == int32(upper>>this.shift) {
- return upper
+ for mask := this.capacity - 1; sequence >= 0; sequence-- {
+ if this.committed[sequence&mask] == int32(sequence>>this.shift) {
+ return sequence
}
}
- return upper
+ return sequence
}