mirror of
https://github.com/tuneinsight/lattigo.git
synced 2025-09-13 03:27:14 +00:00
29 lines
418 B
Go
29 lines
418 B
Go
package structs
|
|
|
|
import "sync"
|
|
|
|
type BufferPool[T any] interface {
|
|
Get() T
|
|
Put(T)
|
|
}
|
|
type SyncPool[T any] struct {
|
|
pool *sync.Pool
|
|
}
|
|
|
|
func NewSyncPool[T any](f func() T) *SyncPool[T] {
|
|
pool := &sync.Pool{
|
|
New: func() any {
|
|
return f()
|
|
},
|
|
}
|
|
return &SyncPool[T]{pool: pool}
|
|
}
|
|
|
|
func (spool *SyncPool[T]) Get() T {
|
|
return spool.pool.Get().(T)
|
|
}
|
|
|
|
func (spool *SyncPool[T]) Put(buff T) {
|
|
spool.pool.Put(buff)
|
|
}
|