reuseF func(*T) *T
poolF func(*T) *T
buf []*T
- sync.RWMutex
+ l sync.RWMutex
}
// 创建池
return t
}
+func (t *Buf[T]) PoolInUse() (inUse int) {
+ t.l.RLock()
+ defer t.l.RUnlock()
+
+ for i := 0; i < len(t.buf); i++ {
+ if t.inUse(t.buf[i]) {
+ inUse++
+ }
+ }
+
+ return
+}
+
+func (t *Buf[T]) PoolSum() int {
+ t.l.RLock()
+ defer t.l.RUnlock()
+
+ return len(t.buf)
+}
+
func (t *Buf[T]) Trim() {
- t.Lock()
- defer t.Unlock()
+ t.l.Lock()
+ defer t.l.Unlock()
for i := 0; i < len(t.buf); i++ {
if !t.inUse(t.buf[i]) {
}
func (t *Buf[T]) Get() *T {
- t.Lock()
- defer t.Unlock()
+ t.l.Lock()
+ defer t.l.Unlock()
for i := 0; i < len(t.buf); i++ {
if !t.inUse(t.buf[i]) {
return
}
- t.Lock()
- defer t.Unlock()
+ t.l.Lock()
+ defer t.l.Unlock()
var cu = 0
for i := 0; i < len(t.buf); i++ {