コード例 #1
0
ファイル: common.go プロジェクト: roger2000hk/flib
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
ファイル: pqarl.go プロジェクト: roger2000hk/flib
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
ファイル: common.go プロジェクト: roger2000hk/flib
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
ファイル: common.go プロジェクト: roger2000hk/flib
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
}