2020-02-23 12:35:47 +01:00
|
|
|
package netstorage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
2020-12-08 19:49:32 +01:00
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
|
2020-02-23 12:35:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// GetInsertCtx returns InsertCtx from the pool.
|
|
|
|
//
|
|
|
|
// Call PutInsertCtx for returning it to the pool.
|
|
|
|
func GetInsertCtx() *InsertCtx {
|
|
|
|
select {
|
|
|
|
case ctx := <-insertCtxPoolCh:
|
|
|
|
return ctx
|
|
|
|
default:
|
|
|
|
if v := insertCtxPool.Get(); v != nil {
|
|
|
|
return v.(*InsertCtx)
|
|
|
|
}
|
|
|
|
return &InsertCtx{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// PutInsertCtx returns ctx to the pool.
|
|
|
|
//
|
|
|
|
// ctx cannot be used after the call.
|
|
|
|
func PutInsertCtx(ctx *InsertCtx) {
|
|
|
|
ctx.Reset()
|
|
|
|
select {
|
|
|
|
case insertCtxPoolCh <- ctx:
|
|
|
|
default:
|
|
|
|
insertCtxPool.Put(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var insertCtxPool sync.Pool
|
2020-12-08 19:49:32 +01:00
|
|
|
var insertCtxPoolCh = make(chan *InsertCtx, cgroup.AvailableCPUs())
|