Remove backup files

non-blocking
Jack Christensen 2022-06-04 08:59:53 -05:00
parent f1df39a29d
commit 73398bc67a
2 changed files with 0 additions and 151 deletions

View File

@ -1,76 +0,0 @@
package nbbconn
import (
"sync"
"github.com/jackc/pgx/v5/internal/iobufpool"
)
const minBufferQueueLen = 8
type bufferQueue struct {
lock sync.Mutex
queue [][]byte
r, w int
}
func (bq *bufferQueue) pushBack(buf []byte) {
bq.lock.Lock()
defer bq.lock.Unlock()
if bq.w >= len(bq.queue) {
bq.growQueue()
}
bq.queue[bq.w] = buf
bq.w++
}
func (bq *bufferQueue) pushFront(buf []byte) {
bq.lock.Lock()
defer bq.lock.Unlock()
if bq.w >= len(bq.queue) {
bq.growQueue()
}
copy(bq.queue[bq.r+1:bq.w+1], bq.queue[bq.r:bq.w])
bq.queue[bq.r] = buf
bq.w++
}
func (bq *bufferQueue) popFront() []byte {
bq.lock.Lock()
defer bq.lock.Unlock()
if bq.r == bq.w {
return nil
}
buf := bq.queue[bq.r]
bq.queue[bq.r] = nil // Clear reference so it can be garbage collected.
bq.r++
if bq.r == bq.w {
bq.r = 0
bq.w = 0
if len(bq.queue) > minBufferQueueLen {
bq.queue = make([][]byte, minBufferQueueLen)
}
}
return buf
}
func (bq *bufferQueue) growQueue() {
desiredLen := (len(bq.queue) + 1) * 3 / 2
if desiredLen < minBufferQueueLen {
desiredLen = minBufferQueueLen
}
newQueue := make([][]byte, desiredLen)
copy(newQueue, bq.queue)
bq.queue = newQueue
}
func releaseBuf(buf []byte) {
iobufpool.Put(buf[:cap(buf)])
}

View File

@ -1,75 +0,0 @@
package nbbconn
import (
"sync"
)
const minQueueLen = 8
type queue[T any] struct {
lock sync.Mutex
queue []T
r, w int
}
func (q *queue[T]) pushBack(item T) {
q.lock.Lock()
defer q.lock.Unlock()
if q.w >= len(q.queue) {
q.growQueue()
}
q.queue[q.w] = item
q.w++
}
func (q *queue[T]) pushFront(item T) {
q.lock.Lock()
defer q.lock.Unlock()
if q.w >= len(q.queue) {
q.growQueue()
}
copy(q.queue[q.r+1:q.w+1], q.queue[q.r:q.w])
q.queue[q.r] = item
q.w++
}
func (q *queue[T]) popFront() (T, bool) {
q.lock.Lock()
defer q.lock.Unlock()
if q.r == q.w {
var zero T
return zero, false
}
item := q.queue[q.r]
// Clear reference so it can be garbage collected.
var zero T
q.queue[q.r] = zero
q.r++
if q.r == q.w {
q.r = 0
q.w = 0
if len(q.queue) > minQueueLen {
q.queue = make([]T, minQueueLen)
}
}
return item, true
}
func (q *queue[T]) growQueue() {
desiredLen := (len(q.queue) + 1) * 3 / 2
if desiredLen < minQueueLen {
desiredLen = minQueueLen
}
newQueue := make([]T, desiredLen)
copy(newQueue, q.queue)
q.queue = newQueue
}