first-commit

This commit is contained in:
harshabose
2025-02-18 16:44:58 +05:30
parent f91d9277bb
commit be46bbacb8
5 changed files with 166 additions and 2 deletions

View File

@@ -1 +1,43 @@
package internal
import (
"sync"
"github.com/asticode/go-astiav"
)
type packetPool struct {
pool sync.Pool
}
func (pool *packetPool) Get() *astiav.Packet {
packet, ok := pool.pool.Get().(*astiav.Packet)
if packet == nil || !ok {
return astiav.AllocPacket()
}
return packet
}
func (pool *packetPool) Put(packet *astiav.Packet) {
if packet == nil {
return
}
packet.Unref()
pool.pool.Put(packet)
}
func (pool *packetPool) Release() {
for {
packet, ok := pool.pool.Get().(*astiav.Packet)
if packet == nil {
break
}
if !ok {
continue
}
packet.Free()
}
}