Пример #1
0
func (q *commonQ) readWrappingBuffer(bufferSize int64) (from int64, to int64, wrap int64) {
	readTo := q.read.Value + bufferSize
	if readTo > q.writeCache.Value {
		q.writeCache.Value = atomic.LoadInt64(&q.write.Value)
		if readTo > q.writeCache.Value {
			q.failedReads.Value++
			return 0, 0, 0
		}
	}
	from = q.read.Value & q.mask
	to = fmath.Min(from+bufferSize, q.size)
	wrap = bufferSize - (to - from)
	return from, to, wrap
}
Пример #2
0
func pqarlEnqueue(msgCount int64, q *spscq.PointerQ, batchSize int64, done chan bool) {
	runtime.LockOSThread()
	t := int64(1)
	var buffer []unsafe.Pointer
	for t < msgCount {
		size := fmath.Min(batchSize, msgCount-t)
		buffer = q.AcquireWrite(size)
		for buffer == nil {
			buffer = q.AcquireWrite(size)
		}
		for i := range buffer {
			t++
			buffer[i] = unsafe.Pointer(uintptr(uint(t)))
		}
		q.ReleaseWriteLazy()
	}
	done <- true
}
Пример #3
0
func (q *commonQ) acquireRead(bufferSize int64) (from int64, to int64) {
	read := q.read.Value
	from = read & q.mask
	bufferSize = fmath.Min(bufferSize, q.size-from)
	readTo := read + bufferSize
	to = from + bufferSize
	if readTo > q.writeCache.Value {
		q.writeCache.Value = atomic.LoadInt64(&q.write.Value)
		if readTo > q.writeCache.Value {
			to = q.writeCache.Value & q.mask
		}
	}
	if from == to {
		q.failedReads.Value++
	}
	q.readSize.Value = to - from
	return from, to
}
Пример #4
0
func (q *commonQ) acquireWrite(bufferSize int64) (from int64, to int64) {
	write := q.write.Value
	from = write & q.mask
	bufferSize = fmath.Min(bufferSize, q.size-from)
	writeTo := write + bufferSize
	readLimit := writeTo - q.size
	to = from + bufferSize
	if readLimit > q.readCache.Value {
		q.readCache.Value = atomic.LoadInt64(&q.read.Value)
		if readLimit > q.readCache.Value {
			to = q.readCache.Value & q.mask
		}
	}
	if from == to {
		q.failedWrites.Value++
	}
	q.writeSize.Value = to - from
	return from, to
}