1
0
mirror of https://github.com/fumiama/orbyte.git synced 2026-06-10 21:24:50 +08:00

fix: count items

This commit is contained in:
源文雨
2025-05-13 00:52:42 +09:00
parent e8afcce73a
commit 23a2b71205
2 changed files with 10 additions and 13 deletions

16
pool.go
View File

@@ -106,7 +106,7 @@ func (pool *Pool[T]) newempty() *Item[T] {
return item.setautodestroy()
}
func (pool *Pool[T]) put(item *Item[T]) {
func (pool *Pool[T]) put(item *Item[T], hasignore bool) {
runtime.SetFinalizer(item, nil)
item.cfg = nil
@@ -118,15 +118,17 @@ func (pool *Pool[T]) put(item *Item[T]) {
return
}
_, exist := pool.dupmap.LoadOrStore(item, struct{}{})
if exist {
panic("duplicated put")
if !hasignore {
_, exist := pool.dupmap.LoadOrStore(item, struct{}{})
if exist {
panic("duplicated put")
}
pool.pool.Put(item)
pool.incin()
}
pool.pool.Put(item)
pool.decout()
pool.incin()
}
// New call this to generate an item.