go_dreamfactory/comm/pool.go
2023-10-18 11:35:48 +08:00

45 lines
869 B
Go

package comm
import (
"go_dreamfactory/pb"
"sync"
)
var buriedParamPool = &sync.Pool{
New: func() interface{} {
return &pb.BuriedParam{
Value: 0,
Filter: make([]int32, 0),
}
},
}
// 普通任务
func GetBuriedParam(t TaskType, vaule int32, p ...int32) *pb.BuriedParam {
task := buriedParamPool.Get().(*pb.BuriedParam)
task.TaskType = int32(t)
task.Value = vaule
if len(p) > 0 {
task.Filter = append(task.Filter, p...)
}
return task
}
// 统计型任务
func GetBuriedParam2(t TaskType, statistics string, p ...int32) *pb.BuriedParam {
task := buriedParamPool.Get().(*pb.BuriedParam)
task.TaskType = int32(t)
task.Statistics = statistics
if len(p) > 0 {
task.Filter = append(task.Filter, p...)
}
return task
}
func PutburiedParam(r *pb.BuriedParam) {
r.Filter = r.Filter[:0]
r.Value = 0
r.Statistics = ""
buriedParamPool.Put(r)
}