Ejemplo n.º 1
0
func (q *PointerQ) ReadSingleLazy() unsafe.Pointer {
	val := q.readSingle()
	if val != nil {
		fatomic.LazyStore(&q.read.Value, q.read.Value+1)
	}
	return val
}
Ejemplo n.º 2
0
func (q *PointerQ) WriteSingleLazy(val unsafe.Pointer) bool {
	b := q.writeSingle(val)
	if b {
		fatomic.LazyStore(&q.write.Value, q.write.Value+1)
	}
	return b
}
Ejemplo n.º 3
0
func (q *BatchQ) ReadSingle() unsafe.Pointer {
	read := q.read
	if read == q.writeCache {
		q.writeCache = atomic.LoadInt64(&q.write)
		if read == q.writeCache {
			return nil
		}
	}
	val := q.ringBuffer[read&q.mask]
	fatomic.LazyStore(&q.read, q.read+1)
	return val
}
Ejemplo n.º 4
0
func (q *BatchQ) WriteSingle(val unsafe.Pointer) bool {
	write := q.write
	readLimit := write - q.size
	if readLimit == q.readCache {
		q.readCache = atomic.LoadInt64(&q.read)
		if readLimit == q.readCache {
			return false
		}
	}
	q.ringBuffer[write&q.mask] = val
	fatomic.LazyStore(&q.write, q.write+1)
	return true
}
Ejemplo n.º 5
0
func (q *PointerQ) Read() unsafe.Pointer {
	read := q.read.Value
	if read == q.writeCache.Value {
		q.writeCache.Value = atomic.LoadInt64(&q.write.Value)
		if read == q.writeCache.Value {
			return nil
		}
	}
	idx := read & q.mask
	val := q.ringBuffer[idx]
	fatomic.LazyStore(&q.read.Value, q.read.Value+1)
	return val
}
Ejemplo n.º 6
0
func (q *PointerQ) Write(val unsafe.Pointer) bool {
	write := q.write.Value
	readLimit := write - q.size
	if readLimit >= q.readCache.Value {
		q.readCache.Value = atomic.LoadInt64(&q.read.Value)
		if readLimit >= q.readCache.Value {
			return false
		}
	}
	idx := write & q.mask
	q.ringBuffer[idx] = val
	fatomic.LazyStore(&q.write.Value, q.write.Value+1)
	return true
}
Ejemplo n.º 7
0
func (q *ChunkQ) Read() bool {
	chunk := q.chunk
	read := q.read.Value
	readTo := read + chunk
	if readTo > q.writeCache.Value {
		q.writeCache.Value = atomic.LoadInt64(&q.write.Value)
		if readTo > q.writeCache.Value {
			return false
		}
	}
	idx := read & q.mask
	nxt := idx + chunk
	copy(q.readBuffer, q.ringBuffer[idx:nxt])
	fatomic.LazyStore(&q.read.Value, read+chunk)
	return true
}
Ejemplo n.º 8
0
func (q *ChunkQ) Write() bool {
	chunk := q.chunk
	write := q.write.Value
	writeTo := write + chunk
	readLimit := writeTo - q.size
	if readLimit > q.readCache.Value {
		q.readCache.Value = atomic.LoadInt64(&q.read.Value)
		if readLimit > q.readCache.Value {
			return false
		}
	}
	idx := write & q.mask
	nxt := idx + chunk
	copy(q.ringBuffer[idx:nxt], q.writeBuffer)
	fatomic.LazyStore(&q.write.Value, write+chunk)
	return true
}
Ejemplo n.º 9
0
func (q *ByteQ) Read(readBuffer []byte) bool {
	read := q.read.Value
	write := q.writeCache.Value
	if read == write {
		q.writeCache.Value = atomic.LoadInt64(&q.write.Value)
		write = q.writeCache.Value
		if read == write {
			return false
		}
	}
	chunk := min(write-read, int64(len(readBuffer)))
	idx := read & q.mask
	nxt := idx + chunk
	if nxt <= q.size {
		copy(readBuffer, q.ringBuffer[idx:nxt])
	} else {
		mid := q.size - idx
		copy(readBuffer[:mid], q.ringBuffer[idx:])
		copy(readBuffer[mid:], q.ringBuffer)
	}
	fatomic.LazyStore(&q.read.Value, q.read.Value+chunk)
	return true
}
Ejemplo n.º 10
0
func (q *ByteQ) Write(writeBuffer []byte) bool {
	chunk := int64(len(writeBuffer))
	write := q.write.Value
	writeTo := write + chunk
	readLimit := writeTo - q.size
	if readLimit > q.readCache.Value {
		q.readCache.Value = atomic.LoadInt64(&q.read.Value)
		if readLimit > q.readCache.Value {
			return false
		}
	}
	idx := write & q.mask
	nxt := idx + chunk
	if nxt <= q.size {
		copy(q.ringBuffer[idx:nxt], writeBuffer)
	} else {
		mid := q.size - idx
		copy(q.ringBuffer[idx:], writeBuffer[:mid])
		copy(q.ringBuffer, writeBuffer[mid:])
	}
	fatomic.LazyStore(&q.write.Value, q.write.Value+chunk)
	return true
}
Ejemplo n.º 11
0
func (q *ByteChunkQ) ReleaseReadLazy() {
	fatomic.LazyStore(&q.read.Value, q.read.Value+q.chunk)
}
Ejemplo n.º 12
0
func (q *ByteChunkQ) ReleaseWriteLazy() {
	fatomic.LazyStore(&q.write.Value, q.write.Value+q.chunk)
}
Ejemplo n.º 13
0
func (q *LLChunkQ) CommitRead() {
	fatomic.LazyStore(&q.read.Value, q.read.Value+q.chunk)
}
Ejemplo n.º 14
0
func (q *LLChunkQ) CommitWrite() {
	fatomic.LazyStore(&q.write.Value, q.write.Value+q.chunk)
}
Ejemplo n.º 15
0
func (q *BatchQ) CommitWriteBuffer(writeSize int64) {
	fatomic.LazyStore(&q.write, q.write+writeSize)
}
Ejemplo n.º 16
0
func (q *BatchQ) CommitReadBuffer(readSize int64) {
	fatomic.LazyStore(&q.read, q.read+readSize)
}
Ejemplo n.º 17
0
func (q *commonQ) ReleaseReadLazy() {
	fatomic.LazyStore(&q.read.Value, q.read.Value+q.readSize.Value)
	q.readSize.Value = 0
}
Ejemplo n.º 18
0
func (q *commonQ) ReleaseWriteLazy() {
	fatomic.LazyStore(&q.write.Value, q.write.Value+q.writeSize.Value)
	q.writeSize.Value = 0
}