func (s *multiWriterBarrier) calculateAvailabilityFlag(sequence int64) int32 {
	return int32(sequence >> s.indexShift)
}
The availability "flag" is a "lap counter", sequence / ring size
package queue
import (
	"sync/atomic"
)
type barrier interface {
	publish(lo, hi int64)
	waitFor(sequence int64) int64
}
type multiWriterBarrier struct {
	bufferSize   int64
	waitStrategy WaitStrategy
	dependentSequence *sequence
	availableBuffer []int32
	indexMask  int64
	indexShift uint
}
func (b *multiWriterBarrier) publish(lo, hi int64) {
	for l := lo; l <= hi; l++ {
		b.setAvailable(l)
	}
	b.waitStrategy.SignalAllWhenBlocking()
}
func (b *multiWriterBarrier) setAvailable(sequence int64) {
	b.setAvailableBufferValue(b.calculateIndex(sequence), b.calculateAvailabilityFlag(sequence))
}
func (b *multiWriterBarrier) waitFor(sequence int64) int64 {
	published := b.waitStrategy.WaitFor(sequence, b.dependentSequence)
	if published < sequence {
		return published
	}
	high := b.getHighestPublishedSequence(sequence, published)
	return high
}
func (b *multiWriterBarrier) getHighestPublishedSequence(lowerBound, availableSequence int64) int64 {
	for sequence := lowerBound; sequence <= availableSequence; sequence++ {
		if !b.isAvailable(sequence) {
			return sequence - 1
		}
	}
	return availableSequence
}
func (b *multiWriterBarrier) isAvailable(sequence int64) bool {
	return atomic.LoadInt32(&b.availableBuffer[b.calculateIndex(sequence)]) == b.calculateAvailabilityFlag(sequence)
}